No, you cannot trust the variable $_FILES['userfile']['type'] . The value present in this variable can be faked. You can use finfo_file to more reliably determine the file type:
$finfo = finfo_open(FILEINFO_MIME_TYPE); // we need mime type echo finfo_file($finfo, "/path/to/uploaded/file"); // displays something like image/gif finfo_close($finfo);
These functions require PHP> = 5.3.0.
Salman a
source share