paulferree Posted February 14, 2008 Share Posted February 14, 2008 Hey guys, I'm new to PHP. I'm trying to have a file uploaded by a form but I get this error message and I can't figure out why it's not working. I even copied the exact code from PHPs site. Any help would be appreciated? This is what is produced when the script is run. (the upload directory is set to 777 BTW) Tageted Directory: /uploaded_images/logo.gif Sorry, there was a problem uploading your file. Array ( [uploaded] => Array ( [name] => logo.gif [type] => image/gif [tmp_name] => /tmp/phpW5dLdq [error] => 0 => 8575 ) ) Thanks! Paulo Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/ Share on other sites More sharing options...
mem0ri Posted February 14, 2008 Share Posted February 14, 2008 Can you help us out by posting the actual code that you're running? It's impossible to debug something when we can't see it. Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466829 Share on other sites More sharing options...
paulferree Posted February 14, 2008 Author Share Posted February 14, 2008 Sorry: HERES THE FORM: <form enctype="multipart/form-data" action="file_uploaded.php" method="POST"> Please choose a file: <input name="uploaded" type="file" /><br /> <input type="submit" value="Upload" /> </form> HERE'S THE PHP <?php $target = "/uploaded_images/"; $target = $target . basename( $_FILES['uploaded']['name']) ; echo "Tageted Directory: ". $target; if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo '<pre>'; echo "Sorry, there was a problem uploading your file.</br>"; print_r($_FILES); echo '</pre>'; } ?> Thanks, Paul Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466841 Share on other sites More sharing options...
revraz Posted February 14, 2008 Share Posted February 14, 2008 Look at your target directory. Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466850 Share on other sites More sharing options...
paulferree Posted February 14, 2008 Author Share Posted February 14, 2008 /uploaded_images/ That's my directory. Is there something wrong in the code that I'm missing? I checked and its set to 777. Thanks Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466856 Share on other sites More sharing options...
rhodesa Posted February 14, 2008 Share Posted February 14, 2008 Yeah, your target starts with a slash, telling the sever it's an absolute path. I assume you are looking for a relative path (ie the folder uploaded_images is in the same folder as the php script). If that is true, just remove the leading slash: $target = "uploaded_images/"; Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466860 Share on other sites More sharing options...
paulferree Posted February 14, 2008 Author Share Posted February 14, 2008 Well, I thought that might have been the problem when I was trying upload to a deeper directory, so for testing purposes I just put a folder at the root called "uploaded_images"... Paul Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466862 Share on other sites More sharing options...
rhodesa Posted February 14, 2008 Share Posted February 14, 2008 here is the PHP with more debug info added, let us know what it outputs now: <?php $target = "/uploaded_images/"; echo "Tageted Directory: {$target}<br>"; if(!is_dir($target)) die("Dir doesn't exist"); if(!is_writable($target)) die("Dir is not writable"); $target = $target . basename( $_FILES['uploaded']['name']); echo "Saving to file: {$target}<br>"; 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.</br>"; print_r($_FILES); } ?> Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466866 Share on other sites More sharing options...
paulferree Posted February 14, 2008 Author Share Posted February 14, 2008 Tageted Directory: /uploaded_images/ Dir doesn't exist Ergh....but the directory does exist... I'm sorry, I hope I'm not being a complete idiot! Paul Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466882 Share on other sites More sharing options...
haku Posted February 14, 2008 Share Posted February 14, 2008 So remove the leading slash and make sure there is a directory called uploaded_images in the same file as the script. Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466891 Share on other sites More sharing options...
paulferree Posted February 14, 2008 Author Share Posted February 14, 2008 Well, that worked!!! But I don't understand why it wouldn't work when I had the /script_directory/uploaded_images Thanks for the help!!!!! Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466895 Share on other sites More sharing options...
Daniel0 Posted February 14, 2008 Share Posted February 14, 2008 It works because in your code it looked for a folder in the root of the hd. Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466898 Share on other sites More sharing options...
rhodesa Posted February 14, 2008 Share Posted February 14, 2008 Is this on a hosting service? Cus the folder structure you see in your FTP client isn't always the full system path Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466901 Share on other sites More sharing options...
paulferree Posted February 14, 2008 Author Share Posted February 14, 2008 Ok...I can understand that then. Thanks for the help!! I'm sure there will be more q's in the future. You've been great. Paul Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-466959 Share on other sites More sharing options...
rhodesa Posted February 14, 2008 Share Posted February 14, 2008 If you are interested in finding the true system path to a specific file put this line in a php file: echo __FILE__; Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-467022 Share on other sites More sharing options...
haku Posted February 15, 2008 Share Posted February 15, 2008 Nice! I didn't know that little piece of code. I'm definitely filing it away for future reference. Link to comment https://forums.phpfreaks.com/topic/91088-file-upload-problem-newbie/#findComment-467336 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.