vannia Posted October 22, 2009 Share Posted October 22, 2009 Hi there, I need to upload a file, so far i can upload it but when i tried to read it there's no file. Ive checked /tmp's permissions and they're 777 ( drwxrwxrwx. 32 root root ) my php.ini has file_uploads=ON & upload_temp_dir =/tmp/ Here's my code so far... it Outputs a tmp file such as /tmp/phpTEq4Ri/logo.jpg, followed by " NO FILE UPLOAD ERROR" and "CANNOT OPEN FILE" <?php if(isset($_FILES['foto']) && !empty($_FILES['foto']['name'])) { $dir = $_FILES['foto']['tmp_name']; $file= $_FILES['foto']['name']; echo $dir.'/'.$file; switch($_FILES['foto']['error']){ case (0): echo "NO FILE UPLOAD ERROR<br>"; break; } if (!@fopen($dir.'/'.$file, "r")) { echo "CANNOT OPEN FILE"; $foto="''"; } else echo "FILE OPENED"; } else echo "NO FILE UPLOAD"; ?> </html> <head></head> <body> <form name='test' action='fileUp.php' method='post' enctype='multipart/form-data'> <input type='file' name='foto'> <input type='submit'> </form> </body> </html> Thanks Link to comment https://forums.phpfreaks.com/topic/178638-solved-file-upload-ok-but-cant-read-tmp-is-777/ Share on other sites More sharing options...
Daniel0 Posted October 22, 2009 Share Posted October 22, 2009 Have a look at move_uploaded_file. Link to comment https://forums.phpfreaks.com/topic/178638-solved-file-upload-ok-but-cant-read-tmp-is-777/#findComment-942249 Share on other sites More sharing options...
vannia Posted October 22, 2009 Author Share Posted October 22, 2009 I've tried it and it returns false $movedFile=move_uploaded_file($dir.'/'.$file,$dir2.'/'.$file); I read somewhere that an uploaded file can be removed even before you read it, is this true? thansk again Link to comment https://forums.phpfreaks.com/topic/178638-solved-file-upload-ok-but-cant-read-tmp-is-777/#findComment-942323 Share on other sites More sharing options...
bestrong Posted October 22, 2009 Share Posted October 22, 2009 I am assuming that you are uploading the file from a PHP form. If so make sure the form tag is similar to : <form enctype="multipart/form-data" action="your_file.php" method="POST"> Ben Link to comment https://forums.phpfreaks.com/topic/178638-solved-file-upload-ok-but-cant-read-tmp-is-777/#findComment-942331 Share on other sites More sharing options...
vannia Posted October 22, 2009 Author Share Posted October 22, 2009 yes, teh form is included in the original post <form name='test' action='fileUp.php' method='post' enctype='multipart/form-data'> ... Link to comment https://forums.phpfreaks.com/topic/178638-solved-file-upload-ok-but-cant-read-tmp-is-777/#findComment-942338 Share on other sites More sharing options...
bestrong Posted October 22, 2009 Share Posted October 22, 2009 Sorry, I did not scroll down in the code box. $_FILES["foto"]["tmp_name"] returns the name of the temporary copy of the file stored on the server not the directory AND $_FILES["foto"]["name"] returns the name of the file you uploaded...it is not stored on the server by this name. So, what I would do is : $path="directory/images/".$_FILES['foto']['name']; move_uploaded_file($_FILES['foto']['tmp_name'], $path); you are getting an error because there is no directory /tmp/phpTEq4Ri and no file logo.jpg Link to comment https://forums.phpfreaks.com/topic/178638-solved-file-upload-ok-but-cant-read-tmp-is-777/#findComment-942352 Share on other sites More sharing options...
vannia Posted October 22, 2009 Author Share Posted October 22, 2009 Thanks, it makes sense, still i cant get move_uploaded_file to return true ... <?php if(isset($_FILES['foto']) && !empty($_FILES['foto']['name'])) { $tmp_name = $_FILES['foto']['tmp_name']; // temporary copy $file_name= $_FILES['foto']['name']; // uploaded...not stored on the server $full_path="tmp/".$file_name; echo "moving ".$tmp_name." to ".$full_path."..."; $moved_file=move_uploaded_file($tmp_name, $fullpath); if (!$moved_file) echo "File could not be moved "; } else echo "NO FILE UPLOAD"; ?> the code above returns : moving /tmp/phpydZ5jQ to tmp/face.jpeg...File could not be moved Link to comment https://forums.phpfreaks.com/topic/178638-solved-file-upload-ok-but-cant-read-tmp-is-777/#findComment-942401 Share on other sites More sharing options...
bestrong Posted October 22, 2009 Share Posted October 22, 2009 Ok, found the error, you are going to kick yourself $full_path="tmp/".$file_name; notice the "$full_path" $moved_file=move_uploaded_file($tmp_name, $fullpath); now notice the "$fullpath" compare "$full_path" with "$fullpath" Actually, I had to look a while too Have a good one, Ben oh and check out my website (www.bluebeanstalk.com) and pass the word along Link to comment https://forums.phpfreaks.com/topic/178638-solved-file-upload-ok-but-cant-read-tmp-is-777/#findComment-942425 Share on other sites More sharing options...
vannia Posted October 23, 2009 Author Share Posted October 23, 2009 You're right, i do want to kick myself fixed $full_path and it still didn't work, then i also changed $full_path="tmp/".$file_name; to $full_path="/tmp/".$file_name; (adding "/" ) and that did it ! I'm a happy camper .. Thank you VERY VERY much Happy weekend Link to comment https://forums.phpfreaks.com/topic/178638-solved-file-upload-ok-but-cant-read-tmp-is-777/#findComment-942894 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.