My php code for upload is supposed to filter out images with file extentions different than the ones below and bigger than 5 Mb.
It's a normal post fileField form in html that runs this php script.
It works like a charm on Firefox and Chrome, but for some reason doesn't work on Internet Explorer. Only dies "Format not allowed or size too big."
Does anyone have any idea why?

Thank you in advance. Jaklins

<?php
$name = $_FILES["fileField"]["name"];
$type = $_FILES["fileField"]["type"];
$size = $_FILES["fileField"]["size"];
$temp = $_FILES["fileField"]["tmp_name"];
$error = $_FILES["fileField"]["error"]; 

if($error > 0)
	die("Nothing to upload.");
else

if ($size < 5000000 
  && ($_FILES["fileField"]["type"] == "image/jpg"
  || $_FILES["fileField"]["type"] == "image/jpeg"
  || $_FILES["fileField"]["type"] == "image/jpe" 
  || $_FILES["fileField"]["type"] == "image/jfif" 
  || $_FILES["fileField"]["type"] == "image/png" 
  || $_FILES["fileField"]["type"] == "image/gif"
  || $_FILES["fileField"]["type"] == "image/tga" 
  || $_FILES["fileField"]["type"] == "image/rle" 
  || $_FILES["fileField"]["type"] == "image/emf" 
  || $_FILES["fileField"]["type"] == "image/wmf"))
{
	move_uploaded_file($temp, "ITVTE/images/".$name);
	echo "<center> Uploaded.";
}
else
{
	die("Format not allowed or size too big.");
}
?>

I think you need to correct line 12, don't quote me but I think 5MB in bytes is 5242880.

the error is not in the code suplied
php runs on the server, this code must be ok as it works

show the code of the upload form page, likely one of IE's document quirks has been triggered by that form

Here is the entire html code:
The text is in Swedish. The relevant part starts on line 30.

<!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>TE</title>
<style type="text/css">
<!--
.WijkmanskasInternTV {
	font-size: 24px;
	text-align: center;
}
.WijkmanskasInternTV table tr td p {
	text-align: center;
}
.text {
	font-size: 16px;
	text-align: center;
}
-->
</style>
</head>

<body class="WijkmanskasInternTV">
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
  <tr>
    <th bgcolor="#999999"><img src="Ikon.jpg" alt="" width="264" height="175" /></th>
  </tr>
</table>
<p>Infoga objekt för teknikens TV</p>
<form action="uploadTE.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
  <p><span class="text">
  Filnamnet får ej innehålla &aring;, &auml;, &ouml;. <br /> 
  Tillåtna filformat är .jpg, .jpeg, .jpe, .jfif, .png, .gif, .tga, .rle, .emf, .wmf. <br /> 
  Ett av dem ej tillåtna format är .bmp.<br />
  <p><span class="text">
  Infoga bild:
    <input name="fileField" type="file" id="fileField" size="30" />
  </span>    </p>
  <p><span class="text">
    <input type="submit" name="button" id="button" value="Ladda upp" />
  </span></p></form>
<p>Skriv in ett meddelande direkt i webbläsaren</p>
<form action="snabbmeddelandeTE.html" method="post" enctype="multipart/form-data">
  <p>
    <input type="submit" name="button3" id="button3" value="Snabbmeddelande" />
  </p>
</form>
  <p>&nbsp;</p>
<form action="previewTE.php" method="post" enctype="multipart/form-data">
  <p>
    <input type="submit" name="button2" id="button2" value="Visa och redigera innehåll" />
  </p>
</form>
<p class="text"><a href="VäljTV.html">Tillbaka</a></p>
</body>
</html>

I've noticed an unclosed <p> and <span>, but that didn't fix the problem. I'm posting the code as is, because it's not mine. A former member of my group wrote it and I have to say I've had a lot of trouble fixing the, supposedly working, codes he left behind.
WAMP server is being used to host this page.
I appreciate the help almostbob.
Jaklins

I think you may have to change file size that is specified in your php.ini in the apache server. As I can slightly remember the line, it is " upload size maximum" or something like this. Because by default, it only allows you to upload a maximum of 4 MB, I think.

And in your HTML form, you may also have to add this line after your submit button.
The below code is just an example to illustrate to you.

File to upload: <input type="file" name="userfile" size="20" /> <br />
	<input type="submit" value="submit" />
	
	<!-- MAX FILE SIZE IN BYTES -->
        <!-- You add the size in value atrribute and it's BYTES -->

	<input type="hidden" name="MAX_FILE_SIZE" value=" ...">

I hope this helps.

which version of IE you used?

which version of IE you used?

All of them of course (7,8,9). I wouldn't post otherwise.

I think you may have to change file size that is specified in your php.ini in the apache server. As I can slightly remember the line, it is " upload size maximum" or something like this. Because by default, it only allows you to upload a maximum of 4 MB, I think.

And in your HTML form, you may also have to add this line after your submit button.
The below code is just an example to illustrate to you.

File to upload: <input type="file" name="userfile" size="20" /> <br />
	<input type="submit" value="submit" />
	
	<!-- MAX FILE SIZE IN BYTES -->
        <!-- You add the size in value atrribute and it's BYTES -->

	<input type="hidden" name="MAX_FILE_SIZE" value=" ...">

I hope this helps.

Well, if the uploading is restricted by php, the how come it works i other browsers? Just to be on the safe side, i changed the limit to 2000000 for testing purposes. Still doesn't work. The default in php.ini said 2M, I changed it to 6, but it worked with 5 in the netscape browsers anyway.
I added the html line, it didn't help. The max size is already being filtered in php, it would be unnecessary to filter it in html too.

Also, while playing with the code I discovered that if I erase everything that comes between the ampersands (&&) and the first closing parenthesis, the upload will work. So for some some reason IE has a problem with filtering file extensions which works on e.g. firefox. But why?

I'd be very happy with firefox working. I have stopped IE for development reasons. It also crashes all the time !

Good luck with it, mate.

Out of curiosity, what type of file are you using to test your upload script (in IE)?

I'd be very happy with firefox working. I have stopped IE for development reasons. It also crashes all the time !

Good luck with it, mate.

Yeah, well, I have to get it to work on IE because most of the people who are going to use it, use IE. Just because it comes with the OS.

Out of curiosity, what type of file are you using to test your upload script (in IE)?

If you mean what I think you mean, then I'll tell you I'm using .php for the upload. The html form is in .html. I've tried putting it in a separate .php and it didn't help. For the purpose of testing it's in .html, but ultimately we'll put it in .php because the login is in .php and has to be on every page of the website.

Is there any other way to filter those file extensions out that I don't know about?

Hey Jaklins, sorry I should have been more clear, I did mean the type of file you're using to upload with your script (jpg, png etc). IE is known for sending different mime-types than Firefox or any other web browser.

commented: Well spotted! +6

@MrDJK, you're right.
@Jaklins, IE has different known for MIME-TYPE. You'll probably know that echo the file type. IE shows 'jpg' as 'pjpeg' and 'png' as 'x-png'. So, the upload will be done with adding a few lines for those MIME types.

$_FILES["fileField"]["type"] == "image/pjpeg" //for jpeg, and jpg
$_FILES["fileField"]["type"] == "image/x-png" //for png

Hope that solve, and credit to MrDJK.

commented: Thanks for elaborating more. (: +1

Hey Jaklins, sorry I should have been more clear, I did mean the type of file you're using to upload with your script (jpg, png etc). IE is known for sending different mime-types than Firefox or any other web browser.

@MrDJK, you're right.
@Jaklins, IE has different known for MIME-TYPE. You'll probably know that echo the file type. IE shows 'jpg' as 'pjpeg' and 'png' as 'x-png'. So, the upload will be done with adding a few lines for those MIME types.

$_FILES["fileField"]["type"] == "image/pjpeg" //for jpeg, and jpg
$_FILES["fileField"]["type"] == "image/x-png" //for png

Hope that solve, and credit to MrDJK.

Oh my God! It works! Thank you MrDJK and Zero13! I didn't even think of that! This forum rocks!

SOLVED!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.