Image Mime Type Problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • chunk1978
    New Member
    • Jan 2007
    • 224

    Image Mime Type Problem

    hi. i have this mime-type array in my php upload script... but my mime type for photoshop files isn't working. what's wrong with this?

    Code:
    # -=-=-=- Allowed File Extensions:  .TIF / .PSD / .JPG / .JPEG / .JPE / .PNG
    
    $mimetypes = array
    (
    'image/tiff',
    'image/vnd.adobe.photoshop',
    'image/jpeg',
    'image/png',
    );
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Try

    Code:
    print($_FILES['whateverYouCalledIt']['type'];
    exit;
    To see why it's not matching.

    [EDIT: Incidentally, if you made the array keys the accepted types, your script would execute a tiny bit faster as it could use a reference instead of have to loop through the entire array to find a matching MIME type.

    E.g.:

    Code:
    $mimetypes = array
    (
    'image/tiff', => true,
    'image/vnd.adobe.photoshop', => true,
    'image/jpeg', => true,
    'image/png', => true
    );
    
    if(! $mimetypes[$_FILES['whateverYouCalledIt']['type']]) {
        header('Location:  somepage.php?message=MIME_TYPE_MISMATCH');
        exit;
    }
    The other advantage of doing this is that if you wanted to temporarily disable support for a particular mime-type, you could just set its value to false instead of deleting it or commenting it out).
    ]

    Comment

    Working...