andrewgarn Posted May 19, 2008 Share Posted May 19, 2008 The upload works find in firefox, but in ie it always gives the error "Only gif, jpeg can be uploaded" whether the file type is one of those or not Html page: <h2><img src="upload.png" alt="upload" width="400" height="60" /></h2> Select an image to upload:<br> <form action="uploader.php" method="post" enctype="multipart/form-data"> <input type="file" name="file" size="40"><br> Enter Description: <br><input type="text" name="notes" VALUE="" SIZE="40"><br><br> <input type="submit" value="Upload File"> </form> if( $_FILES['file']['name'] != "" ) { if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png")) { copy ( $_FILES['file']['tmp_name'], "gallery/" . $_FILES['file']['name'] ) or die ( "Could not copy file" ); $filename = $_FILES['file']['name']; echo $filename; $query = "INSERT INTO photo (uploader, filename, notes) VALUES ('$uploader', '$filename', '$description');"; //echo $query; $result = mysql_query($query) or die(mysql_error()); } else { die ( "Only gif, jpeg can be uploaded" ); } } oh and thanks for looking Link to comment https://forums.phpfreaks.com/topic/106362-solved-whats-wrong-with-this-upload-script/ Share on other sites More sharing options...
rhodesa Posted May 19, 2008 Share Posted May 19, 2008 what happens when you use this for your die: die ( "Only gif, jpeg can be uploaded. You supplied: ".$_FILES["file"]["type"] ); Also, please post your HTML from the form Link to comment https://forums.phpfreaks.com/topic/106362-solved-whats-wrong-with-this-upload-script/#findComment-545192 Share on other sites More sharing options...
andrewgarn Posted May 19, 2008 Author Share Posted May 19, 2008 what happens when you use this for your die: die ( "Only gif, jpeg can be uploaded. You supplied: ".$_FILES["file"]["type"] ); Also, please post your HTML from the form It says this: Only gif, jpeg can be uploaded. You supplied: image/pjpeg But the file i'm uploading is definitely a .jpg Link to comment https://forums.phpfreaks.com/topic/106362-solved-whats-wrong-with-this-upload-script/#findComment-545203 Share on other sites More sharing options...
rhodesa Posted May 19, 2008 Share Posted May 19, 2008 It's a 'progressive jpeg'. Firefox doesn't support them, therefore won't send that content-type (it just sends them as normal jpeg). It should be fine to add it to your allowed list. May I also recommend cleaning up your code a little with an array: if( $_FILES['file']['name'] != "" ) { $allowed = array( "image/gif", "image/jpeg", "image/pjpeg", "image/jpg", "image/png", ); if (in_array($_FILES["file"]["type"],$allowed)) { Link to comment https://forums.phpfreaks.com/topic/106362-solved-whats-wrong-with-this-upload-script/#findComment-545211 Share on other sites More sharing options...
andrewgarn Posted May 19, 2008 Author Share Posted May 19, 2008 Thank you, that worked. are there any other types like that I should be aware of? and thank you for the code cleanup Link to comment https://forums.phpfreaks.com/topic/106362-solved-whats-wrong-with-this-upload-script/#findComment-545218 Share on other sites More sharing options...
rhodesa Posted May 19, 2008 Share Posted May 19, 2008 hum...not off the top of my head, but if you have GD enabled, you can use the getimagesize() function to test if it's an image. Just make sure you block errors with an @: if(@getimagesize($_FILES['file']['tmp_name'])){ Link to comment https://forums.phpfreaks.com/topic/106362-solved-whats-wrong-with-this-upload-script/#findComment-545231 Share on other sites More sharing options...
andrewgarn Posted May 19, 2008 Author Share Posted May 19, 2008 Thanks Link to comment https://forums.phpfreaks.com/topic/106362-solved-whats-wrong-with-this-upload-script/#findComment-545242 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.