Northern Flame Posted August 9, 2007 Share Posted August 9, 2007 I want users of my website to be able to submit songs or images to me, so i created an upload form but the script that processes it gives me an error message, heres the error message Warning: move_uploaded_file(pending/image/a.JPG): failed to open stream: No such file or directory in /my_path/download/thanks.php on line 19 Warning: move_uploaded_file(): Unable to move '/tmp/phphaMD5R' to 'pending/image/a.JPG' in /my_path/download/thanks.php on line 19 Heres the script <?php $type = $_POST['type']; if($type == 'song'){ $t_path = 'pending/song/'; } elseif($type == 'image'){ $t_path = 'pending/image/'; } else{ $t_path = 'pending/'; } $t_path = $t_path . basename( $_FILES['file']['name']); include('includes/headernf.php'); echo '<div id=body>'; if(move_uploaded_file($_FILES['file']['tmp_name'], $t_path)){ echo " The ".$type." ".basename($_FILES['file']['name'])." has been uploaded! Thank you for contributing to this site!"; } else{ echo " Their was an error when uploading your ".$type.". It is possible that the file was too big. Please try again or <a href='/contact.php'> contact us</a>."; } echo '</div>'; ?> Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/ Share on other sites More sharing options...
teng84 Posted August 10, 2007 Share Posted August 10, 2007 this is always seems to be the prob i guess we have to have something like this on top of this board now the prob is that the path is not correct it is stated here No such file or directory in /my_path/download/thanks.php on line 19 now echo your path and check if that is really what your trying to access Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319817 Share on other sites More sharing options...
Northern Flame Posted August 10, 2007 Author Share Posted August 10, 2007 do you mean the entire path starting from the root, or just the domain leading to the directory where i want it all moved? Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319828 Share on other sites More sharing options...
teng84 Posted August 10, 2007 Share Posted August 10, 2007 $t_path i guess thats only u need to echo Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319829 Share on other sites More sharing options...
SirChick Posted August 10, 2007 Share Posted August 10, 2007 ignore i just misread what you were asking Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319831 Share on other sites More sharing options...
Northern Flame Posted August 10, 2007 Author Share Posted August 10, 2007 it says that the directory does not exist Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319834 Share on other sites More sharing options...
teng84 Posted August 10, 2007 Share Posted August 10, 2007 ok i guess try this its from w3school very cool and basic <?php if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/pjpeg") && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } it says that the directory does not exist this means again the path is incorrect Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319844 Share on other sites More sharing options...
Northern Flame Posted August 10, 2007 Author Share Posted August 10, 2007 alright then, let me customize it to fit my needs, test it out, and report back the results, thanks Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319845 Share on other sites More sharing options...
climbjm Posted August 10, 2007 Share Posted August 10, 2007 Check to make sure that your File that is executing the script has the proper permissions and the folder that you are writing the file to has the correct permissions. When I don't have the permissions set correctly or assigned to the wrong group, I often get that error message (or something almost identical to it). Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319850 Share on other sites More sharing options...
Northern Flame Posted August 10, 2007 Author Share Posted August 10, 2007 alright i told me it was uploaded to a temporary folder, but once again, error message: Warning: move_uploaded_file(upload/nf.gif): failed to open stream: No such file or directory in /my_path/download/thanks.php on line 25 Warning: move_uploaded_file(): Unable to move '/tmp/phpmfDVem' to 'upload/nf.gif' in /my_path/download/thanks.php on line 25 Stored in: pending/nf.gif and it was never stored in the folder "pending/" Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319852 Share on other sites More sharing options...
teng84 Posted August 10, 2007 Share Posted August 10, 2007 whaosssss!!!! look move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]); "upload/" is the folder or the dir $_FILES["file"]["name"] the name of the file you are uploading in your case you dont change this upload/ as your own dir Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319855 Share on other sites More sharing options...
Northern Flame Posted August 10, 2007 Author Share Posted August 10, 2007 oh, haha, i only saw two "upload/" in the script, i didnt notice the third one Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319857 Share on other sites More sharing options...
Northern Flame Posted August 10, 2007 Author Share Posted August 10, 2007 once again :'( :-\ Warning: move_uploaded_file(pending/nf.gif): failed to open stream: No such file or directory in /my_path/download/thanks.php on line 25 Warning: move_uploaded_file(): Unable to move '/tmp/phplnee6o' to 'pending/nf.gif' in /my_path/download/thanks.php on line 25 Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319858 Share on other sites More sharing options...
teng84 Posted August 10, 2007 Share Posted August 10, 2007 LOL HAAAAAAAAAAAAAHAAAAAAA your funny any way wait ill think of better way to see your prob Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319862 Share on other sites More sharing options...
Northern Flame Posted August 10, 2007 Author Share Posted August 10, 2007 lol alright thanks Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319863 Share on other sites More sharing options...
teng84 Posted August 10, 2007 Share Posted August 10, 2007 ok tell me from what folder is this script ? is the image folder also inside this folder or the file is in your root dir and pending/image/ this mean that image is inside pending folder ? Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319870 Share on other sites More sharing options...
Northern Flame Posted August 10, 2007 Author Share Posted August 10, 2007 mysite.com/download/script.php i want them entered to mysite.com/download/pending/ Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319871 Share on other sites More sharing options...
teng84 Posted August 10, 2007 Share Posted August 10, 2007 move_uploaded_file($_FILES["file"]["tmp_name"],"pending/" . $_FILES["file"]["name"]); this should work if not try to put the whole path or can you show me your site to see the error Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319881 Share on other sites More sharing options...
teng84 Posted August 10, 2007 Share Posted August 10, 2007 http://w3schools.com/php/php_file_upload.asp Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-319888 Share on other sites More sharing options...
climbjm Posted August 10, 2007 Share Posted August 10, 2007 When I lower the permissions on the folder that I am writing too, I get errors just like you are showing. Do you have access to your servers shell? I really think you have a permissions not set correctly on your pending folder. If you have access to a shell, type... sudo chmod 0777 /FULLPATH/pending/ example... my upload folder for my website is located here: /var/www/upload/ so I would chmod my folder like this... sudo chmod 0777 /var/www/upload Once you get your permissions fixed and ruled out, then you can tighten your permissions to increase security. * sudo means you are basically running as a super user. * the chmod part tells the computer you want to change the permissions of the file in regards to read, write and execute. * the 0777 basically makes it so that everyone can read/write/execute (full permissions). * Last but not least you give the file or the folder you want to apply the permissions to. IF YOU DO NOT HAVE SHELL ACCESS TO YOUR SERVER... You can actually write a PHP script to do this for you. It goes something like this... Example from http://us3.php.net/chmod <?php chmod("/somedir/somefile", 755); // decimal; probably incorrect chmod("/somedir/somefile", "u+rwx,go+rx"); // string; incorrect chmod("/somedir/somefile", 0755); // octal; correct value of mode ?> LAST BUT NOT LEAST... I promise I am almost done... Here is another great tutorial about creating scripts to upload files. http://www.tizag.com/phpT/fileupload.php As said in the tutorial, when a file is uploaded to your server... it is there only temporarily until the script finishes executing. Once the script finishes (which can be just milliseconds to execute) it destroys those temporary files. This is why when you looked in the folder, you did not see the file. This is actually why you are 'copying' the temp file, into a different folder. That way when the script finishes and deletes the temp file, you still have a copy else where . Quote Link to comment https://forums.phpfreaks.com/topic/64174-upload-file-error/#findComment-320125 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.