Jump to content

[SOLVED] PHP Image Upload - problems with IE


Padgoi

Recommended Posts

So I have a small script and it works fine in other browsers, but the people who use IE are having problems.  They keep getting an error, "You tried to upload wrong file."  Not sure why it's happening.  Here's the PHP part of the script:

 

		if($_FILES['imgfile1']['name'] != '')
	{
		$img_arr = array('','image/jpeg', 'image/gif', 'image/jpg', 'image/GIF', 'image/JPEG', 'image/JPG');
		if(array_search($_FILES['imgfile1']['type'], $img_arr))
		{
			$target_path = "userimages/";			
			$target_path = $target_path . basename($_FILES['imgfile1']['name']); 
			if(move_uploaded_file($_FILES['imgfile1']['tmp_name'], $target_path))
			{
				$imgfile1 = basename( $_FILES['imgfile1']['name']);
				$image1 = $imgfile1;
			}
			else
			{
				header("Location:signup.php?log=Image uploading failed, select image to upload");
				exit;
			}
		}
		else
		{
			header("Location:signup.php?log=You tried to upload wrong file");
			exit;
		}
	}
	else
	{
		header("Location:signup.php?log=Upload an image for your profile.");
		exit;
	}

 

And the HTML part:

 

<tr>
      <td>Picture</td>
      <td><input name="imgfile1" type="file" id="imgfile1" /></td>
    </tr>
      <td><input type="submit" name="Submit" value="Submit" /></td>

 

Why is IE the only browser having this issue?  Any help would be greatly appreciated.  Thanks!

Link to comment
https://forums.phpfreaks.com/topic/57888-solved-php-image-upload-problems-with-ie/
Share on other sites

try...

$img_arr = array( 

'image/pjpeg' => 'jpg',

'image/jpeg' => 'jpg',

'image/jpeg' => 'jpeg',

'image/gif' => 'gif',

'image/X-PNG' => 'png',

'image/PNG' => 'png',

'image/png' => 'png',

'image/x-png' => 'png',

'image/JPG' => 'jpg',

'image/GIF' => 'gif',

'image/bmp' => 'bmp',

'image/bmp' => 'BMP',

);

The problem is that you're checking MIME types, and IE does not use the standard image/jpeg anymore (sorry, I've forgetten the new one!  Looking for it now!).

 

Just to make sure this is the problem, try changing the following:

 

else
		{
			header("Location:signup.php?log=You tried to upload wrong file");
			exit;
		}

To:

 

else
		{
			echo 'Wrong MIME type';
			exit;
		}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.