[SOLVED] mime type isn't right somehow

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
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

[SOLVED] mime type isn't right somehow

Post by ryuuka »

i got this site that needs to upload files and it only needs accept
zip files this is where the weird part comes in

i echo'ed everything and it says everything is a zip (even pdf's and psd files) file when i do this:

Code: Select all

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

if ($type = 'application/x-zip-compressed'){ 

//stuff

}
else
{
echo "this file is nozip file <br>";
echo "new upload";
}
and when i do this it does everything correct, it even gives the correct filetype

Code: Select all

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

if ($type != 'application/x-zip-compressed'){ 

//stuff

}
else
{
echo "this file is a  zip file <br>";
echo "new upload";
}
really weird

ps: please don't start about the safety and correctness of the $_files
variable. it serves my purpose well enough and my users are a bunch of ignorants :)
and no one from outside can get into this server
Last edited by ryuuka on Mon Jan 15, 2007 7:47 am, edited 1 time in total.
ryuuka
Forum Contributor
Posts: 128
Joined: Tue Sep 05, 2006 8:18 am
Location: the netherlands

Post by ryuuka »

NM
i already solved it

Code: Select all

if ($type != 'application/x-zip-compressed')
{
echo "het bestand is geen zip file <br>";
echo "probeer een ander bestand te uploaden";
} 
else
{
//stuff
}
i have no idea why this works and the other thing doesn't
but frankly i don't give a damn as long as it works
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Zip files can come in several content-types. Type information fed to you from the browser is absolutely unreliable 100% of the time. Check the file data itself.

mime_content_type() may be of use.
Post Reply