View Full Version : Check content type in PHP

01-29-2012, 06: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;

01-29-2012, 07: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

01-29-2012, 07:13 PM

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.

01-29-2012, 07: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..