I'm uploading some files. Below is part of the script for the upload (I'm using codes from https://github.com/blueimp/jQuery-File-Upload/blob/master/php/index.php)
$upload = isset($_FILES[$this->options['param_name']]) ?
$_FILES[$this->options['param_name']] : null;
$info = array();
if ($upload && is_array($upload['tmp_name'])) {
foreach ($upload['tmp_name'] as $index => $value) {
$info[] = $this->handle_file_upload(
$upload['tmp_name'][$index],
isset($_SERVER['HTTP_X_FILE_NAME']) ?
$_SERVER['HTTP_X_FILE_NAME'] : $upload['name'][$index],
isset($_SERVER['HTTP_X_FILE_SIZE']) ?
$_SERVER['HTTP_X_FILE_SIZE'] : $upload['size'][$index],
isset($_SERVER['HTTP_X_FILE_TYPE']) ?
$_SERVER['HTTP_X_FILE_TYPE'] : $upload['type'][$index],
$upload['error'][$index]
);
}
When checked, the mime type through $_SERVER['HTTP_X_FILE_TYPE']
or $upload['type'][$index]
returns application/vnd.openxmlformats-officedocument.presentationml.presentation
, application/vnd.openxmlformats-officedocument.wordprocessingml.document
for pptx
, docx
files respectively.
Now after completing the upload, I'm trying to display the files and I'm using finfo_file()
to get the mime type.
$mime_type = finfo_file(finfo_open(FILEINFO_MIME_TYPE), $file_path);
echo $mime_type;
For images files (like png, jpeg) & pdf, the type returns as expected but for the pptx
and docx
files, the mime type returned is application/zip
.
Why is it not returning the same as while in uploading? Is there something wrong with my code or should I expect this? How do I decide which file type it is then?