Jump to content

Recommended Posts

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?  :shrug:

Link to comment
https://forums.phpfreaks.com/topic/166933-solved-uploader-not-working-in-ie/
Share on other sites

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?

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!

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.