Reputation: 37
I am trying to check the mime type of an uploaded file before I move it but I cannot get finfo_file
to return anything.
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['imageFile']['tmp_name']);
echo $mime;
// returns NOTHING!
...so just to test in finfo_file is available and the file path is good:
echo phpversion();
// returns 5.1.28
$finfo = finfo_open(FILEINFO_MIME_TYPE);
foreach (glob("*") as $filename) {
echo finfo_file($finfo, $filename) . ', ';
}
// returns text/plain, text/html, image/png, directory, text/x-asm, text/x-php, text/x-php, text/x-php, directory, directory
echo move_uploaded_file($_FILES['imageFile']['tmp_name'], getcwd().'/uploadsTemp/'. uniqid());
// returns 1
Can it be that somehow finfo_file
cannot read the file?
Upvotes: 2
Views: 2565
Reputation: 26
I believe, it (finfo_file
) returns not just mime type, but text description of the contents of the file. Visit.this.page
Try to use this $imageinfo['mime']
. Maybe it helps!
And there can be one suggestion, but I am not sure, why must you use $_FILES['imageFile']['tmp_name']
instead of $_FILES['imageFile']['name']
? Is it so important to use temporary file?
Upvotes: 0
Reputation: 29
Today I had the same problem and this was caused because the uploaded file was larger than the upload_max_filesize in php.ini.
I just notice it here since I could not find this solution in other posts.
Upvotes: 2
Reputation: 43
This might be a stupid answer as there may be many reasons why you can't use this but...
Can you not just use $_FILES["Img"]["type"]
and use the MIME types given by that?
Sorry if that doesn't answer your question.
Upvotes: -1