Mime Type PDF php upload
27,911
Solution 1
You forgot to break before the default case :)
By the way, for the sake of answering your direct question, I've found myself referring back to this thread over and over again: Proper MIME media type for PDF files
Solution 2
Try this and
if ($_FILES['tax']['error'] !== UPLOAD_ERR_OK)
die("Upload failed with error " . $_FILES['tax']['error']);
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mime = finfo_file($finfo, $_FILES['tax']['tmp_name']);
$ok = false;
switch ($mime) {
case 'image/gif':
break;
case 'application/pdf':
break;
case 'image/png':
$ok = true;
break;
default:
die("Unknown/not permitted file type");
break;
}
move_uploaded_file($_FILES["tax"]["tmp_name"],"pints/" . $_FILES["tax"]["name"]);
If won't solve your problem then tell us how do finfo_open
and finfo_file
functions look like.
Author by
kira423
There really isn't much I can say about myself except I like coding in my spare time, my preferred language is PHP. I think I am still on a beginner level, so I may ask more questions than I actually answer, but I hope to get much better quickly!
Updated on January 22, 2020Comments
-
kira423 over 4 years
I have this snippet
if ($_FILES['tax']['error'] !== UPLOAD_ERR_OK) { die("Upload failed with error " . $_FILES['tax']['error']); } $finfo = finfo_open(FILEINFO_MIME_TYPE); $mime = finfo_file($finfo, $_FILES['tax']['tmp_name']); $ok = false; switch ($mime) { case 'image/gif': case 'application/pdf': case 'image/png': $ok = true; default: die("Unknown/not permitted file type"); } move_uploaded_file($_FILES["tax"]["tmp_name"],"pints/" . $_FILES["tax"]["name"]);
When I try to upload the image it states that it isn't a permitted file type, when the file is a PDF document, is
application/pdf
the correct mime type?