能有人給我如何使用fileinfo
,更換的代碼片段,如例如:FileInfo的功能PHP
($_FILES["fileToUpload"]["type"] == "image/gif"
|| $_FILES["fileToUpload"]["type"] == "image/jpeg"
|| $_FILES["fileToUpload"]["type"] == "image/png")
能有人給我如何使用fileinfo
,更換的代碼片段,如例如:FileInfo的功能PHP
($_FILES["fileToUpload"]["type"] == "image/gif"
|| $_FILES["fileToUpload"]["type"] == "image/jpeg"
|| $_FILES["fileToUpload"]["type"] == "image/png")
使用此:
$finfo = new finfo();
$fileinfo = $finfo->file($file, FILEINFO_MIME);
$的FileInfo應該包含正確的MIME類型,您可以在類似的代碼片段中使用,或者在switch語句中使用:
switch($fileinfo) {
case "image/gif":
case "image/jpeg":
case "image/png":
// Code
break;
}
$objInfo = new finfo(FILEINFO_MIME);
list($strImageType, $strCharset) = $objInfo->file($_FILES['fileToUpload']['tmp_name']);
//then use the variable $strImageType in your conditional
if ($strImageType == "image/gif" || $strImageType == "image/jpeg" || $strImageType == "image/png") {
//code
}
我爲投票下來道歉,但我無法找到一個例子 – Shawn 2011-03-22 20:26:37