<?php
$finfo = new finfo();
$fileinfo = $finfo->file($_FILES["fileToUpload"]["tmp_name"], FILEINFO_MIME);
switch($fileinfo) {
case "image/gif":
case "image/jpeg":
case "image/png":
move_uploaded_file($_FILES["fileToUpload"]["tmp_name"],
"upload/" . $_FILES["fileToUpload"]["name"]);
echo "Your file has successfully been uploaded, and is awaiting moderator approval for points." . "<html><br><a href='uploadfile.php'>Upload more.</a>";
break;
default:
echo "Files must be either JPEG, GIF, or PNG and less than 10,000 kb";
break;
}
?>
it has recently been brought to my attention there is nothing wrong here, it just doesnt work because my servers php is only at 5.2 lemme know if you guys can find a way to make it work using MIME
pecl install fileinfo
?
http://pecl.php.net/package/Fileinfo
On Linux servers you can be lazy and use:
$type = exec("file -iL " . escapeshellcmd($fn) . " 2>/dev/null");
$type = trim(strtok(substr(strrchr($type, ":"), 1), ";"));
mime_content_type
might still work for you. While it's now under the fileinfo
section in the manual, it existed way before fileinfo
was brought into the PHP core.
Do note that it might require a bit of configuration if your host moved Apache's mime.types
file out of the normal location, as documented in the comments on that page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With