Redlightpacket Posted August 2, 2008 Share Posted August 2, 2008 I know there is a bug in my code or something. I need somebody that could help me make my code work. My code is explained in some parts. I just need my code to upload files to a server. If this code isn't a workable type, just give me some of yours. <!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"> <head> <body> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>File Upload</title> </head> <form enctype="multipart/form-data" action="newphpupload.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="524288" /> <fieldset><legend>Select a JPEG or GIF image to be uploaded: </legend> <p><b>File:</b><input type="file" name="upload" /></p> </fieldset> <div align="center"> <input type="submit" name="submit" vaule="Submit"/></div> <input type="hidden" name="submitted" value="TRUE" /> </form> </body> </html> <?php // Check if the form has been submitted. if (isset($_POST['submitted'])) { //Check for an uploaded file. if(isset($_FILES['/home/www/'])) { // Validate the type. Should be jpeg, jpg, or jif. $allowed = array('image/gif', 'image/jpeg', 'image/jpg'); if (in_array($_FILES['/home/www/']['type'], $allowed)) { // Move the file over if (move_uploaded_file($_FILES['/home/www/']['/home/www/'], "uploads/{$_FILES['/home/www/'] ['name']}")) { echo ' <p> The file has been uploaded!</p>'; } else { // Couldn't move the file over. echo '<p> <font color="red">The file could not be uploaded because: <b>'; // Print a message based upon the error switch($_FILES['upload']['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 'No temporary folder was available.'; break; default: print 'A system error occrured.'; break; print '</br></font>.</p>'; }// End of move... IF. } } else { // Invalid type. echo '<p><font color="red">Please upload a JPEG or GIF image.</font></p>'; echo'<p><font color="red">Please upload a JPEG or GIF image.</font></p>'; unlink($_FILES['upload']['/home/www/']); // Delete the file } } else { // No file uploaded echo 'Please upload a JPEG'; } } // End of the submitted conditional. ?> Link to comment https://forums.phpfreaks.com/topic/117882-need-help-making-a-php-file-upload-script-work-on-a-server/ Share on other sites More sharing options...
MadTechie Posted August 2, 2008 Share Posted August 2, 2008 you have a few mistakes, try this PHP code **UNTESTED* <?php // Check if the form has been submitted. $uploaddir = '/home/www/uploads/'; //I assume this is the upload path if (isset($_POST['submitted'])) { //Check for an uploaded file. if(isset($_FILES['upload']['name'])) { $uploadfile = $uploaddir . basename($_FILES['upload']['name']); // Validate the type. Should be jpeg, jpg, or jif. $allowed = array('image/gif', 'image/jpeg', 'image/jpg'); if (in_array($_FILES['upload']['type'], $allowed)) { // Move the file over if (move_uploaded_file($_FILES['upload']['tmp_name'], $uploadfile)) { echo ' <p> The file has been uploaded!</p>'; } else { // Couldn't move the file over. echo '<p> <font color="red">The file could not be uploaded because: <b>'; // Print a message based upon the error switch($_FILES['upload']['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 'No temporary folder was available.'; break; default: print 'A system error occrured.'; break; }// End of move... IF. print '</br></font>.</p>'; } } else { // Invalid type. echo '<p><font color="red">Please upload a JPEG or GIF image.</font></p>'; echo'<p><font color="red">Please upload a JPEG or GIF image.</font></p>'; unlink($_FILES['upload']['tmp_name']); // Delete the file } } else { // No file uploaded echo 'Please upload a JPEG'; } } // End of the submitted conditional. ?> Link to comment https://forums.phpfreaks.com/topic/117882-need-help-making-a-php-file-upload-script-work-on-a-server/#findComment-606363 Share on other sites More sharing options...
Redlightpacket Posted August 3, 2008 Author Share Posted August 3, 2008 Thanks for the help Link to comment https://forums.phpfreaks.com/topic/117882-need-help-making-a-php-file-upload-script-work-on-a-server/#findComment-606479 Share on other sites More sharing options...
Redlightpacket Posted August 4, 2008 Author Share Posted August 4, 2008 I get these error messages when I put the script on the server. ===================================================================== Warning: move_uploaded_file(/www/codehouse.100webspace.net/ Baby.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/www/codehouse.100webspace.net/newphpupload.php on line 14 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpavQ7Ax' to '/www/codehouse.100webspace.net/ Baby.jpg' in /home/www/codehouse.100webspace.net/newphpupload.php on line 14 The file could not be uploaded because: A system error occrured. ==================================================================== Here is my php code: --------------------- <?php // Check if the form has been submitted. $uploaddir = '/www/codehouse.100webspace.net/ '; //I assume this is the upload path if (isset($_POST['submitted'])) { //Check for an uploaded file. if(isset($_FILES['upload']['name'])) { $uploadfile = $uploaddir . basename($_FILES['upload']['name']); // Validate the type. Should be jpeg, jpg, or jif. $allowed = array('image/gif', 'image/jpeg', 'image/jpg'); if (in_array($_FILES['upload']['type'], $allowed)) { // Move the file over if (move_uploaded_file($_FILES['upload']['tmp_name'], $uploadfile)) { echo ' <p> The file has been uploaded!</p>'; } else { // Couldn't move the file over. echo '<p> <font color="red">The file could not be uploaded because: <b>'; // Print a message based upon the error switch($_FILES['upload']['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 'No temporary folder was available.'; break; default: print 'A system error occrured.'; break; }// End of move... IF. print '</br></font>.</p>'; } } else { // Invalid type. echo '<p><font color="red">Please upload a JPEG or GIF image.</font></p>'; echo'<p><font color="red">Please upload a JPEG or GIF image.</font></p>'; unlink($_FILES['upload']['tmp_name']); // Delete the file } } else { // No file uploaded echo 'Please upload a JPEG'; } } // End of the submitted conditional. ?> Any help would be nice. Link to comment https://forums.phpfreaks.com/topic/117882-need-help-making-a-php-file-upload-script-work-on-a-server/#findComment-607055 Share on other sites More sharing options...
coder500 Posted August 4, 2008 Share Posted August 4, 2008 See this tutorial regarding this. It worked for me. http://www.worth2read.org/php_tutorial8.php You can enter the number of files to be uploaded, then you can select the files and upload them to the server.. Link to comment https://forums.phpfreaks.com/topic/117882-need-help-making-a-php-file-upload-script-work-on-a-server/#findComment-607244 Share on other sites More sharing options...
MadTechie Posted August 4, 2008 Share Posted August 4, 2008 check this line $uploaddir = '/www/codehouse.100webspace.net/ '; //I assume this is the upload path 1. theirs a space at the end ? 2. does it exist ? 3. is it writable ? Link to comment https://forums.phpfreaks.com/topic/117882-need-help-making-a-php-file-upload-script-work-on-a-server/#findComment-607316 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.