dustflower Posted April 3, 2010 Share Posted April 3, 2010 Hello ! i am having issue on uploading and displaying an image in php! i keep getting the errors! "Warning: move_uploaded_file(../uploads/boxing.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\xampp\htdocs\upload_file.php on line 15 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\php122.tmp' to '../uploads/boxing.jpg' in C:\xampp\htdocs\upload_file.php on line 15 i am trying to figure what is wrong but i don't get it " plz help" <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> <head> <meta http-equiv="content-type" content="text/html; charset=utf-8" /> <title>Upload a File</title> </head> <body> <?php // Script 11.4 - upload_file.php /* This script displays and handles an HTML form. This script takes a file upload and stores it on the server. */ if (isset($_POST['submitted'])) { // Handle the form. // Try to move the uploaded file: if (move_uploaded_file ($_FILES['thefile']['tmp_name'], "../uploads/{$_FILES['thefile']['name']}")) { print '<p>Your file has been uploaded.</p>'; } else { // Problem! print '<p style="color: red;">Your file could not be uploaded because: '; // Print a message based upon the error: switch ($_FILES['thefile']['error']) { case 1: print 'The file exceeds the upload_max_filesize setting in php.ini'; break; case 2: print 'The file exceeds the MAX_FILE_SIZE setting in the HTML form'; break; case 3: print 'The file was only partially uploaded'; break; case 4: print 'No file was uploaded'; break; case 6: print 'The temporary folder does not exist.'; break; default: print 'Something unforeseen happened.'; break; } print '.</p>'; // Complete the paragraph. } // End of move_uploaded_file() IF. } // End of submission IF. // Leave PHP and display the form: ?> <form action="upload_file.php" enctype="multipart/form-data" method="post"> <p>Upload a file using this form:</p> <input type="hidden" name="MAX_FILE_SIZE" value="3000000" /> <p><input type="file" name="thefile" /></p> <p><input type="submit" name="submit" value="Upload This File" /></p> <input type="hidden" name="submitted" value="true" /> </form> </body> </html> plz help! Quote Link to comment https://forums.phpfreaks.com/topic/197475-upload-and-display-an-image/ Share on other sites More sharing options...
premiso Posted April 3, 2010 Share Posted April 3, 2010 The uploads directory is not at the location you think it is at. I find it better to use absolute paths over relative. So instead of ../ do something like: $upload_path = $_SERVER['DOCUMENT_ROOT'] . '/path/to/uploads/'; This way you know where the file is going. If you do not want to do that, then the uploads directory should be in this structure: ----ROOT |_____script_folder | |_______uploadscript.php |_____uploads_folder | So the uploads_folder is not at the structure like that. So you need to modify the code or create the folder in the structure setup. Quote Link to comment https://forums.phpfreaks.com/topic/197475-upload-and-display-an-image/#findComment-1036482 Share on other sites More sharing options...
dustflower Posted April 3, 2010 Author Share Posted April 3, 2010 so do i implement it within the the if (move_uploaded_file ($_FILES['thefile']['tmp_name'], "../uploads/{$_FILES['thefile']['name']}")) { section! Quote Link to comment https://forums.phpfreaks.com/topic/197475-upload-and-display-an-image/#findComment-1036495 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.