LiamH Posted July 22, 2009 Share Posted July 22, 2009 Hi all. I have an image uploader which works fine in all browsers, except IE. For some reason when trying to upload any file, even though they have been defined as acceptable, IE states it is an illegal type. <?php // the image upload code has been adapted from an example that is avaialable from http://www.visualdesigncore.com/tutorial.php/PHP-MySQL/PHP-Image-Upload/?do=tut&tut=PHP-Image-Upload // the filepath the image will be saved to on the server, and the maximum filesize in KB the image can be $path = "images/articles/"; define ("maxsize","5120"); // check to see if a file has been selected in the textbox, if it has give it a temporary name on the server, if not do nothing // if a file has been selected the size is then checked. If the file is too big, an error message is displayed and the file is not sent if (!isset($_FILES['image'])) exit; if (is_uploaded_file($_FILES['image']['tmp_name'])) { $size=filesize($_FILES['image']['tmp_name']); if ($size > maxsize*1000) { echo "<td align='center'>The file is too large, please choose an image that is smaller than 5MB in size.</td>"; exit; } // the allowed file types are defined below. Only images with the extensions set out below are allowed. The extension on the selected image is checked if (($_FILES['image']['type']=="image/gif") || ($_FILES['image']['type']=="image/jpeg") || ($_FILES['image']['type']=="image/jpg") || ($_FILES['image']['type']=="image/png")) { // if the filetype is ok, a check is done to see if the file exists on the server. If it does, an error message is displayed and the image is not uploaded if (file_exists($path . $_FILES['image']['name'])) { echo "<td align='center'>This image already exists in the server. Please try another file.</td>"; exit; } $res = copy($_FILES['image']['tmp_name'], $path . $_FILES['image']['name']); if (!$res) { echo "<td align='center'>Upload has failed.</td>"; exit; } // if file passes checks, upload file with success message else { echo "<td align='center' class='confirm'>Image file ".$_FILES['image']['name']." uploaded succesfully.</td>"; } // if file is not correct file type, the other checks are skipped and go straight to an error message stating the file is of the wrong type, and the file is not uploaded } else { echo "<td align='center'>Wrong file type, please select another.</td>"; exit; } } ?> Anyone know why IE is lying to me? Quote Link to comment https://forums.phpfreaks.com/topic/166933-solved-uploader-not-working-in-ie/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 22, 2009 Share Posted July 22, 2009 When a comparison that is being used to validate external data fails, why not echo the value that failed in the error message so that you can see why it failed? Quote Link to comment https://forums.phpfreaks.com/topic/166933-solved-uploader-not-working-in-ie/#findComment-880424 Share on other sites More sharing options...
LiamH Posted July 23, 2009 Author Share Posted July 23, 2009 How would I do it with that code - sorry! Quote Link to comment https://forums.phpfreaks.com/topic/166933-solved-uploader-not-working-in-ie/#findComment-881333 Share on other sites More sharing options...
LiamH Posted July 27, 2009 Author Share Posted July 27, 2009 Anyone? Quote Link to comment https://forums.phpfreaks.com/topic/166933-solved-uploader-not-working-in-ie/#findComment-883832 Share on other sites More sharing options...
JonnoTheDev Posted July 27, 2009 Share Posted July 27, 2009 Do you get an error in IE? Where the reply states echo out the values: echo $_FILES['image']['tmp_name']."<br />"; echo $_FILES['image']['type']."<br />"; echo($path.$_FILES['image']['name'])."<br />"; echo $_FILES['image']['type']; Does everything look correct? Quote Link to comment https://forums.phpfreaks.com/topic/166933-solved-uploader-not-working-in-ie/#findComment-883834 Share on other sites More sharing options...
LiamH Posted July 29, 2009 Author Share Posted July 29, 2009 Hi. IE is the only browser that is causing issues. This works perfectly on all the other browsers. No error messages are being displayed, expect for the message the uploader gives stating it is the wrong image type. Hvaing tried your method, I for some reason have "image/pjpeg" being displayed on the page. Which has stumped me even more. I have no idea why it is saying that! Quote Link to comment https://forums.phpfreaks.com/topic/166933-solved-uploader-not-working-in-ie/#findComment-885838 Share on other sites More sharing options...
LiamH Posted July 29, 2009 Author Share Posted July 29, 2009 Had a go on one of the other browsers with that code in, and it's just IE that for some reason is putting a p in the code. With the code you gave me, it simply displays "image/jpeg" Quote Link to comment https://forums.phpfreaks.com/topic/166933-solved-uploader-not-working-in-ie/#findComment-885842 Share on other sites More sharing options...
LiamH Posted July 29, 2009 Author Share Posted July 29, 2009 Looking into it further, it appears this is a feature of IE Up to this point I was actually enjoying using IE8. Adding it to the MIME has sorted the problem. Thanks for the help guys Quote Link to comment https://forums.phpfreaks.com/topic/166933-solved-uploader-not-working-in-ie/#findComment-885849 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.