rnb_cassanova Posted March 6, 2008 Share Posted March 6, 2008 Hi lads, I am trying to create an upload script. I am using http://uk3.php.net/features.file-upload for advice; Although i am receiving errors. My code is as follows- $uploaddir = '/DV8 System/Uploads/'; // im not sure if this is where the problem is - am i putting the directory in correctly? $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); echo $uploadfile; echo '<pre>'; <form enctype="multipart/form-data" action="ValidatingUploadAdminForm.php" method="POST"> // also should this point to a form of to the upload directory? Cheers in advance lads David Quote Link to comment Share on other sites More sharing options...
yandoo Posted March 6, 2008 Share Posted March 6, 2008 Hi there, i seem to be having a problem with a similar problem, im following this tutorial: http://www.phpriot.com/articles/images-in-mysql/5 I can get the image to upload Error Free No Problem, but to display the image...well i seem to be having problems in that nothing dynamic displays.... Thanks Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 I have looked at yours, your is writing to a DB, mine just uploads to a local folder, thats why im confused by the why im getting so many errors. if anyone can help i would appreciate. Cheers Quote Link to comment Share on other sites More sharing options...
aebstract Posted March 6, 2008 Share Posted March 6, 2008 Can you show more code, put it in [ code ] tags and the errors you are getting would help so we know what to look for? Quote Link to comment Share on other sites More sharing options...
thezaphod042 Posted March 6, 2008 Share Posted March 6, 2008 I dont know if this will help you but this is what I am using. <?php $TofD = $_POST["TofD"]; $target = "files/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ".basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "Sorry, there was a problem uploading your file."; } } ?> and I am calling it from this within the html <form enctype="multipart/form-data" action="upload.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form> It works great. Also if anyone knows how to add list box or selction box to this and reroute the upload please see my thread... Dennis Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 Hi sorry, DV8 System/Uploads/Dave.doc Warning: move_uploaded_file(DV8 System/Uploads/Dave.doc) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\DV8 System\ValidatingUploadAdminForm.php on line 9 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\phpE8A3.tmp' to 'DV8 System/Uploads/Dave.doc' in C:\wamp\www\DV8 System\ValidatingUploadAdminForm.php on line 9 Possible file upload attack! Here is some more debugging info:Array ( [userfile] => Array ( [name] => Dave.doc [type] => application/msword [tmp_name] => C:\wamp\tmp\phpE8A3.tmp [error] => 0 => 28160 ) ) the code is [code <!-- The data encoding type, enctype, MUST be specified as below --> <form enctype="multipart/form-data" action="ValidatingUploadAdminForm.php" method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> ] and <?php // In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead // of $_FILES. $uploaddir = 'DV8 System/Uploads/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); echo $uploadfile; echo '<pre>'; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; ?> sorry its everywhere, if there is a better method of pasting this please let me know. Cheers David Quote Link to comment Share on other sites More sharing options...
rnb_cassanova Posted March 6, 2008 Author Share Posted March 6, 2008 Dennis, That worked perfect, thanks so much for that mate. Really appreciate the help. All the best, David Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.