upload form: file types

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
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

upload form: file types

Post by sh33p1985 »

my upload form should only allow jpegs to be uploaded but the following code keeps identifying jpegs as *not jpegs*:

if ($_FILES['uploadImage']['type'] == "image/jpeg"){
//continue with upload
}
else{
//error handling
}

i double checked the mime for jpeg and that is correct and should cover all alternatives such as jpg jpe and jpeg but i continually get thrown to the else clause.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Do not rely on $_FILES[...]['type']. The value is take from the client's input.
If I like I can send an executable and mark it as mage/jpeg. Your script would buy it.

Use getimagesize, exif_imagetype or mime_content_type instead
http://de2.php.net/getimagesize
http://de2.php.net/exif_imagetype
http://de2.php.net/mime_content_type
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

Post by sh33p1985 »

went with the mime_content_type, uncommented:

extension=php_mime_magic.dll

and added in:

mime_magic.debug = On
mime_magic.magicfile = "C:\Program Files\EasyPHP1-8\php\magic.mime"


still getting a call to undefined function tho at runtime.

if (mime_content_type($filename) == "image/jpeg"){
//blah
}
else{
//blahblah
}
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Did you restart the webserver after you made changes to the php.ini?
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

Post by sh33p1985 »

i did, but to make sure im going to do a system reboot, bare with me.
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

Post by sh33p1985 »

yup still calling an undefined function.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

Call

Code: Select all

<?php phpinfo(); ?>
does it refelect the changes you made to the php.ini?
Change something else, display_errors e.g. Does phpinof() reflect that change?
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

Post by sh33p1985 »

hmm, changed display_errors to off, restarted web server and refreshed my test page with phpinfo() in it. still said errors were on.
sh33p1985
Forum Commoner
Posts: 78
Joined: Thu Mar 11, 2004 9:22 am

Post by sh33p1985 »

fixed it.

thanks for your help though.
Post Reply