wowcrofty Posted July 28, 2010 Share Posted July 28, 2010 I am attempting to develop a PHP media upload script that will be used for a photo/video gallery, but whenever I click the upload button in my HTML document, the file seems to upload and then I receive the error 500 - Internal server error. Could someone be so kind as to indicate what that means or what is incorrect in the following code? media_submit.htm <!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> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Boy Scout Troop 322 of DC: Submit Media</title> <style type="text/css"> .style73 { border-color: #008000; border-width: 0; } .style1 { text-align: center; } .style30 { vertical-align: middle; } .style2 { text-align: center; font-family: "Arial Black"; font-size: x-large; } .style74 { color: #000000; font-size: x-large; } .style75 { font-size: large; } .style77 { font-family: Arial; font-size: medium; } </style> </head> <body style="background-image: url('background.jpg')"> <table style="width: 100%" cellspacing="4" align="center" class="style73"> <tbody> <tr> <td class="style1" style="width: 241px"> <img alt="American Flag" src="American%20Flag.gif" width="161" height="90" /> <br /> </td> <td class="style1" style="width: 241px"> <center> <img alt="Crest" src="Honor%20Crest.gif" width="125" height="122" class="style30"/></center> </td> <td class="style1" style="width: 241px"> <img alt="PA Flag" src="PA%20Flag.gif" width="152" height="96" /> <br /> </td> </tr> <tr> <td class="style2" colspan="3" style="height: 72px"> <table style="width: 101%; height: 119px;" class="style73" cellspacing="0"> <tr> <td> <img alt="Home Banner" src="Submit%20Media%20Banner.png" width="650" height="120" /></td> </tr> <tr> <td class="style74"> S<span class="style75">O, YOU HAVE SOMETHING YOU WOULD LIKE ADDED TO THE WEBSITE? The first step you must take is uploading the file and this can be done by using the form below. You can upload images, videos, sound clips, and documents in virtually any format. Once submitted, our webmaster will review the file and if approved, notify you via email and place the item in the appropriate section of the gallery. <br /> </span> <form enctype="multipart/form-data" method="post" action="upload.php"> <strong><span class="style77">UPLOAD FILE</span><br /> </strong><span class="style75"><br /> </span><span class="style77">Choose File:</span><span class="style75"><input name="file" type="file" /><br /> <input type="submit" value="Upload File" /> </span></form> <br /> <span class="style75">THANK YOU FOR YOUR CONTRIBUTION!</span></td> </tr> </table> </td> </tr> </tbody> </table> </body> </html> upload.php <?php // Where the file is going to be placed $target_path = "file_uploads/"; /*Add the original filename to our target path. Result is "uploads/filename.extension"*/ $target_path=$target_path.basenmae($_FILES['file']['name']) //Move file to upload directory if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { echo "The file ".basename($_FILES['file']['name']). "has been successfully submitted. You will be contacted with status soon."; } else{ echo "There was a problem submitting the file. Plese try again!"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/209063-php-file-upload-code-problem/ Share on other sites More sharing options...
smonkcaptain Posted July 28, 2010 Share Posted July 28, 2010 Does the target folder have sufficient permissions? Quote Link to comment https://forums.phpfreaks.com/topic/209063-php-file-upload-code-problem/#findComment-1091921 Share on other sites More sharing options...
wowcrofty Posted July 28, 2010 Author Share Posted July 28, 2010 I reset the permissions for the folder and that seems to have fixed that problem, but now I am getting: Parse error: syntax error, unexpected T_IF in D:\Hosting\4872190\html\upload.php on line 10 How do I fix this? Quote Link to comment https://forums.phpfreaks.com/topic/209063-php-file-upload-code-problem/#findComment-1091924 Share on other sites More sharing options...
Pikachu2000 Posted July 28, 2010 Share Posted July 28, 2010 Missing line terminating semicolon on previous line . . . Quote Link to comment https://forums.phpfreaks.com/topic/209063-php-file-upload-code-problem/#findComment-1091926 Share on other sites More sharing options...
wowcrofty Posted July 28, 2010 Author Share Posted July 28, 2010 I have fixed that, but now I am getting this when I submit the upload: Warning: move_uploaded_file(/file_uploads/Pasta Dinner Ticket Sales 2010.xls) [function.move-uploaded-file]: failed to open stream: No such file or directory in D:\Hosting\4872190\html\upload.php on line 10 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\phpA521.tmp' to '/file_uploads/Pasta Dinner Ticket Sales 2010.xls' in D:\Hosting\4872190\html\upload.php on line 10 There was a problem submitting the file. Plese try again! My code now looks like this: <?php // Where the file is going to be placed $target_path = "/file_uploads/"; /*Add the original filename to our target path. Result is "uploads/filename.extension"*/ $target_path=$target_path.basename($_FILES['file']['name']); //Move file to upload directory if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) { echo "The file ".basename($_FILES['file']['name']). "has been successfully submitted. You will be contacted with status soon."; } else{ echo "There was a problem submitting the file. Plese try again!"; } ?> Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/209063-php-file-upload-code-problem/#findComment-1091931 Share on other sites More sharing options...
Pikachu2000 Posted July 28, 2010 Share Posted July 28, 2010 It appears to be attempting to move the file to a directory /file_uploads/ at the root of the disk. Is that the correct path? Quote Link to comment https://forums.phpfreaks.com/topic/209063-php-file-upload-code-problem/#findComment-1091934 Share on other sites More sharing options...
wowcrofty Posted July 28, 2010 Author Share Posted July 28, 2010 The upload directory is at the root of the server and is named file_uploads. The reason I added the extra slash before the name was because I consistently receive a 500 Server error if I remove it. The directory has write permission on my web server, but would the following be the correct syntax and if it is, why do I keep getting the server error? $target_path="file_uploads/" Quote Link to comment https://forums.phpfreaks.com/topic/209063-php-file-upload-code-problem/#findComment-1091935 Share on other sites More sharing options...
Pikachu2000 Posted July 28, 2010 Share Posted July 28, 2010 Try this path statement, then try using a filename without spaces in it. $target_path = $_SERVER['DOCUMENT_ROOT'] . "/file_uploads/"; Quote Link to comment https://forums.phpfreaks.com/topic/209063-php-file-upload-code-problem/#findComment-1091936 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.