Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 11 of 11
  1. #1
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,771
    Thanks
    19
    Thanked 155 Times in 146 Posts

    trouble with MIME types

    Is there something wrong with the logic of this code?

    HTML upload form fields:

    Code:
    <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:

    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();
            }

    etcetc.... 
    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.
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #2
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    try echoing out the mime type, so you can compare

  • #3
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    I tried your code and it worked fine with my pngs... perhaps the problem is with your pngs?

  • #4
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,771
    Thanks
    19
    Thanked 155 Times in 146 Posts
    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?
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #5
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    havent a clue, did you try echoing out the mime type to see what it thinks it is?

  • #6
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    Code:
    <form action="uploadfile.php" method="post" enctype="multipart/form-data">
    ...
    </form>
    for your form?

  • #7
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,771
    Thanks
    19
    Thanked 155 Times in 146 Posts
    Quote Originally Posted by NancyJ
    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...

    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
    Regards, R.J.

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!

  • #8
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    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

  • #9
    Senior Coder NancyJ's Avatar
    Join Date
    Feb 2005
    Location
    Bradford, UK
    Posts
    3,172
    Thanks
    19
    Thanked 65 Times in 64 Posts
    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

  • #10
    Senior Coder missing-score's Avatar
    Join Date
    Jan 2003
    Location
    UK
    Posts
    2,194
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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

  • #11
    Senior Coder chump2877's Avatar
    Join Date
    Dec 2004
    Location
    the U.S. of freakin' A.
    Posts
    2,771
    Thanks
    19
    Thanked 155 Times in 146 Posts
    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...

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

    ---------------------------------------------------------

    Help spread the word! Like my YouTube-to-Mp3 Conversion Script on Facebook !! :)
    [Related videos and tutorials are also available at my YouTube channel and on Dailymotion]
    Get free updates about new software version releases, features, and bug fixes!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •