[SOLVED] mime types on some images

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

[SOLVED] mime types on some images

Post by josh »

Code: Select all

<?php
if(mime_content_type($_FILES['userfile']['tmp_name'])==NULL) {
    find_out_whats_wrong
} else {
    upload_it
}
?>
so... whats wrong? It works on most images except every once in a while I'll find an image it wont work on. If I try to upload it when it is == NULL, it puts a file there that matches the size of the uploaded file but its just a "corrupt pic"
Last edited by josh on Thu Nov 11, 2004 12:19 pm, edited 2 times in total.
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Maybe try your luck using a different method to find out what file type it is:

Code: Select all

$_FILES['userfile']['type'];
or

Code: Select all

getimagesize();
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

$_FILES['userfile']['type'];

that returns null

I dont really care about image size right now.. even if I ignore the mime type and upload it regardless the picture will be "corrupt" but i can view it perfectly from my pc.. ive tried openin the image in photoshop and converting to gif/jpg/png etc... all do the same thing...
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

[php_man]getimagesize[/php_man]() returns the mimetype of the image as well as the image size and an nice formatted height, width size for your img tag.

what is the mime type that you are expecting from this corrupt images?
Are they fancy, use special coding techniques or too big?
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Post by josh »

Ohh man i feel soooo stupid

Code: Select all

<input type="hidden" name="MAX_FILE_SIZE" value="30000000000000000000" />
I didn't know that you had to edit the MAX_FILE_SIZE ... i thought i just ran an if statement on the size after it's been uploaded, seems your browser will not send the image if you specify a max_file_size on the form you are sending it from and that exceeds.. in my script I said upload it no matter what file size so that threw me off

I noticed there was an ['error'] field in my array when I decided to print_r($_FILES); and looked it up here:
http://us2.php.net/manual/en/features.f ... errors.php
Post Reply