Can we read the header information of a file in PHP to determine the type of file uploaded?.
I don't want to rely on
finfo_file(). You have to call it passing the filepath. Example:
$finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($finfo, $_FILES['control_name_from_client']['tmp_name']); finfo_close($finfo);
You need the
Fileinfo extension. As PHP manual says:
The functions in this module try to guess the content type and encoding of a file by looking for certain magic byte sequences at specific positions within the file. While this is not a bullet proof approach the heuristics used do a very good job.