chris Posted April 15, 2011 Share Posted April 15, 2011 Hi, I have completed Script 10.3, I spent 3 hours last night debbuging it as it would not work. I would select an image and it did nothing. I was using Firefox and dreamweaver cs4, With windows vista, wamp 2.1 php6.0 Apache2.2.17 Ive been trying again today, nothing just the html form.select an image and press submit, i get the load symbol and the form stay's the same! Then i tried Internet explorer 9, nothing Then Opera 11.0, nothing, Then safari, Wa hey... It works, so i tried google chrome and that works too. I noticed the two browsers that work don't have a text box just a button but they work and the images go to the folder So why do the other three browsers that show a text box display not work, is it the way i have them configured as they are the browers i use and the other two i do not? Here is my Script although it is not that!!! <!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>Upload an image</title> <style type="text/css" title="text/css" media="all"> .error { font_weight: bold; color: #c00; } </style> </head> <body> <?Php # Script 10.3 upload_image.php // Check if the form has been submitted: if (isset($_POST['submitted'])) { // Check for an uploaded file if (isset($_FILES['upload'])) { // Validate the file type, should be JPG or PNG. $allowed = array ('image/pjpeg', 'image/jpeg', 'image/jpeg', 'image/JPG', 'image/X_PNG', 'image/PNG', 'image/png', 'image/x-png'); if (in_array($_FILES['upload'] ['type'], $allowed)) { // Move the file over. if (move_uploaded_file ($_FILES['upload']['tmp_name'], "C:/wamp/uploads/{$_FILES['upload']['name'] }")) { echo '<p><em>The file has been uploaded.</em></p>'; } // End of move IF } else { // Invalid type. echo '<p class="error">Please upload a JPG or PNG image.</p>'; } } //End of isset($_FILES['upload']) IF // Check for an error if ($_FILES['upload']['error'] > 0) { echo '<p class="error">The file could not be upload because: <strong>'; //Print a message based upon the error. switch ($_FILES['upload']['error']) { case 1: print 'This exeeds the max_file_upload setting in php.ini.'; break; case 2: print 'The file size exeeds the MAX_FILE_SIZE in the HTML form'; break; case 3: print 'The file was only partialy uploaded.'; break; case 4: print 'No files were uploaded'; break; case 6: print 'No tempory folder was available.'; break; case 7: print 'Unalble to write to the disk'; break; case 8: print 'File upload stopped'; break; default: print 'A sytem error occured'; break; } // End of switch print '</strong></p>'; } // End of error IF. //Delete the files if it still exists if (file_exists ($_FILES['upload']['tmp_name']) && is_file($_FILES['upload']['tmp_name']) ) { unlink ($_FILES['upload']['tmp_name']); } } // End of the submitted conditional ?> <form enctype="multipart/form_data" action="upload_image.php" method="post"> <input type="hidden" name="MAX_FILE_SIZE" value="524288" > <fieldset><legend>Select a JPG or PNG image of 512kb or smaller to be uploaded:</legend> <p><b>File:</b> <input type="file" name="upload" /></p> </fieldset> <div align="center"><input type="submit" name="submit" value="Submit" /></div> <input type="hidden" name="submitted" value="TRUE" /> </form> </body> </html> Link to comment Share on other sites More sharing options...
Larry Posted April 15, 2011 Share Posted April 15, 2011 The problem is in your script. You have enctype="multipart/form_data" when it should be enctype="multipart/form-data". Link to comment Share on other sites More sharing options...
Recommended Posts