...

View Full Version : trouble with MIME types



chump2877
09-14-2005, 01:56 PM
Is there something wrong with the logic of this code?

HTML upload form fields:


<table border="0" cellpadding="0" width="100%">
<tr>
<td align="right" width="45%"><input type="file" name="upload[1]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[2]"></td>
</tr>
<tr>
<td align="right" width="45%"><input type="file" name="upload[3]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[4]"></td>
</tr>
<tr>
<td align="right" width="45%"><input type="file" name="upload[5]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[6]"></td>
</tr>
<tr>
<td align="right" width="45%"><input type="file" name="upload[7]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[8]"></td>
</tr>
<tr>
<td align="right" width="45%"><input type="file" name="upload[9]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[10]"></td>
</tr>
<tr>
<td align="right" width="45%"><input type="file" name="upload[11]"></td>
<td width="10%"></td>
<td align="left" width="45%"><input type="file" name="upload[12]"></td>
</tr>
</table>

PHP code:


$accepted_mime = array(
'application/excel',
'application/msword',
'application/pdf',
'application/postscript',
'application/ppt',
'application/x-shockwave-flash',
'application/zip',
'application/x-compressed',
'application/x-zip-compressed',
'application/x-javascript',
'application/octet-stream',
'audio/x-wav',
'audio/midi',
'image/gif',
'image/pjpeg',
'image/jpeg',
'image/tiff',
'image/bmp',
'image/png',
'text/html',
'text/x-server-parsed-html',
'text/css',
'text/plain',
'text/richtext',
'video/mpeg'
);

for ($i = 1; $i <= 12; $i++)
{
if (!empty($_FILES['upload']['name'][$i]))
{
// Test for filetype
if (!in_array($_FILES['upload']['type'][$i], $accepted_mime))
{
echo '<br><br><span><b>Sorry, that file type is not accepted.</b></span>';
echo "<br><br><span>Please use your browser's back button to return to the form and fix any errors. <i>Thank you!</i></span><br><br>";
exit();
}

etc, etc....

I'm trying to use this code to upload a .PNG file, but I keep getting the error message:


Sorry, that file type is not accepted.

Please use your browser's back button to return to the form and fix any errors. Thank you!

When I attempt to upload a .JPG or .GIF, I have no problems....the .png file type is listed in my MIME array, so why am I getting this error? Something to do with the .png file type??

Thanks.

NancyJ
09-14-2005, 02:00 PM
try echoing out the mime type, so you can compare

NancyJ
09-14-2005, 02:07 PM
I tried your code and it worked fine with my pngs... perhaps the problem is with your pngs?

chump2877
09-14-2005, 02:34 PM
Yeah, maybe the problem is the .png files themselves...I dunno...but it's the wierdest thing, you know?

What could possibly be wrong with the .png files?

NancyJ
09-14-2005, 02:50 PM
havent a clue, did you try echoing out the mime type to see what it thinks it is?

missing-score
09-14-2005, 02:56 PM
The browser sends the content type, so it is possible your browser isn't sending the type properly, I doubt the PNG images are corrupt otherwise you wouldnt be able to view them.

You can use mime_content_type() server-side to check the mime type.

Finally, are you sure you have used something like:



<form action="uploadfile.php" method="post" enctype="multipart/form-data">
...
</form>


for your form?

chump2877
09-14-2005, 03:33 PM
havent a clue, did you try echoing out the mime type to see what it thinks it is?

I apologize...I should have done that the first time you told me to do that... :rolleyes:

I echoed out the MIME type and it returns 'image/x-png'....I didn;t realize there was more than one type for PNG files...oh well

anyway, it works now, thanks for the help :thumbsup:

NancyJ
09-14-2005, 03:40 PM
The simplest answer is usually the best ;)
It seemed logical to me just to find out what the script/browser thought the file was and allow that type :D

NancyJ
09-14-2005, 03:46 PM
The Internet Assigned Numbers Authority (IANA) has registered "image/png" as the Internet Media Type for PNG [RFC-2045], [RFC-2048]. For robustness, decoders may choose to also support the interim media type "image/x-png" that was in use before registration was complete.

http://www.libpng.org/pub/png/spec/1.2/png-1.2-pdg.html

missing-score
09-14-2005, 03:54 PM
Interesting, although I do recall seeing image/x-png like once in the past, but I just thought it was someone trying to be annoying :P

Glad you got it sorted :thumbsup:

chump2877
09-14-2005, 04:59 PM
The Internet Assigned Numbers Authority (IANA) has registered "image/png" as the Internet Media Type for PNG [RFC-2045], [RFC-2048]. For robustness, decoders may choose to also support the interim media type "image/x-png" that was in use before registration was complete.

lol...well what a complete pain in the rear that is... :D

But that fits because my distributor (the PNG images are of computer systems) lives in the stone age....the forkwads



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum