...

View Full Version : Check content type in PHP



csammy
01-29-2012, 05:53 PM
In PHP, when a script uploads a file from a user, is it possible to check the mime type of the file?

Something like this...

$uploaded_type = METHOD_FOR_GETTING_TYPE_OF_FILE($uploaded);

if ($uploaded_type =="text/php"){
$rejectfile = 1;
}

jmj001
01-29-2012, 06:02 PM
you mean when a user uploads a file to your site right?

if so, yes.. it will be in the $_FILES variable... print_r($_FILES) and you will see it and will be able write code to reject filetypes that you don't want

there's some good info here: http://php.net/manual/en/reserved.variables.files.php

csammy
01-29-2012, 06:13 PM
Awesome!

Any idea on how "effective" this is? Any feedback on if it's pretty effective?

If it's just grabbing the extension and not actually checking the file it may not be much different than what I'm doing currenlty.

jmj001
01-29-2012, 06:17 PM
i 'believe' it does check the mime type... but not 100% sure..

you can easily test it by renaming a file extension and see what the process says it is..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum