I am on shared hosting, and have been battling with them to get fileinfo working, we have finally got it working, but again I have been hit with another barrier, I have essentially got this because I am creating a new file upload tool and we need to know what mimetypes are being uploaded, but fileinfo does not want to play ball.
So, a .sql file will return text/plain, correct.
However, every other file will simply return application/octet-stream, what I am wondering is why this is the case, I don't want to be pissing the host off with tons of questions so I want to get some research on the issue before I hassle them furthur.
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, many thanks
Update
So I have gone about updating the code of the MIMETYPE check, and I have 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 have made it output failed when it, fails. This is happening 100% of the time, and removing that if statement causes it to return application/octet-stream, which is incorrect.
The upload process will be: User uploads -> Files are moved to a temporary folder above public, (upload_check) where they will be checked by fileinfo, if the file is not what we accept it will be discarded, else it will be copied to the public files and and then discarded from the temporary folder.
I have created that process, and still fileinfo doesn't want to co-operate and returns application/octet-stream for everything, even though they are on the server just saved above the public_html folder.
Any advice?
Jake