I am on a shared hosting and fighting with them to get fileinfo to work, we finally got it working, but again I was hit by another barrier, I basically got it because I am creating a new file download and we need to know which mimetypes loaded, but fileinfo does not want to play ball.
So, the .sql file will return the text / plain, correctly.
However, every other file simply returns the application / octet stream, I wonder why this is so, I donβt want you to write a lot of questions about this to the host, so I want to get some research on this issue before I bother them.
the code:
function get_mime($filename) { $result = new finfo(FILEINFO_MIME_TYPE, "/usr/share/file/magic.mime"); return $result->file($filename, FILEINFO_MIME_TYPE); } echo $user->get_mime($_FILES['file']['tmp_name'][$i]);
Any help would be greatly appreciated, thank you very much
Update
So, I went to update the MIMETYPE verification code, and I updated the code to reflect the following (for the function):
function get_mime($filename) { $result = new finfo(FILEINFO_MIME_TYPE, "/usr/share/file/magic.mime"); // return mime type ala mimetype extension if (is_resource($result) === true) { return $result->file($filename, FILEINFO_MIME_TYPE); } else { return "failed"; } return false; }
Obviously, as you can see, I concluded that it failed when it does not work. This happens 100% of the time, and deleting this if statement causes it to return the application / octet stream, which is incorrect.
The download process will be: User uploads β Files are moved to a temporary folder above the public folder (upload_check), where they will be checked by the file if the file is not what we accept, it will be dropped, otherwise it will be copied to public files and then discarded from temporary folder.
I created this process and still fileinfo does not want to collaborate and returns the application / octet stream for everything, even if they are on a server just saved above the public_html folder.
Any tips?
Jake