Reputation: 1330
When I echo the file type of a docx file, it seems to be cut off. Does any one has any idea where I might be wrong?
$strInputFile = "test.docx;
echo $file_type = $_FILES[$strInputFile]["type"]; // gives application/vnd.openxmlformats-officedocument.word
Thanks
Upvotes: 1
Views: 670
Reputation: 1330
The file type to compare was getting saved to the database and it was getting cut of from there. Increased the field value size in db and its working fine now.
Upvotes: 0
Reputation: 8696
This is not the fault of PHP - but the client used to upload the file. Checking the manual shows that the ['type'] value is set by the client.
An alternative is to pass through mime_content_type() or finfo_file() in PHP 5.3 or newer - these use a 'magic' file on your server to determine the file's MIME type.
Note, that even this is not infallible, as the functions search for fingerprints in the files to determine the MIME type (example, I've often had CSS files detected as C# because I had a /* comment at the top of the file).
Upvotes: 1