復制代碼 代碼如下:
 
extension=php_fileinfo.dll 
復制代碼 代碼如下:
 
extension=fileinfo.so 
#如不能正常工作,再加上下面這條 
#mime_magic.magicfile=/usr/share/file/magic 
復制代碼 代碼如下:
 
function getFileMimeType($file) { 
$buffer = file_get_contents($file); 
$finfo = new finfo(FILEINFO_MIME_TYPE); 
return $finfo->buffer($buffer); 
} 
$mime_type = getFileMimeType($file); 
switch($mime_type) { 
case "image/jpeg": 
// your actions go here... 
} 
復制代碼 代碼如下:
 
// 假設file input 域的name 屬性為myfile 
$tempFile = $_FILES['myFile']['tmp_name']; // path of the temp file created by PHP during upload 
$imginfo_array = getimagesize($tempFile); // returns a false if not a valid image file 
if ($imginfo_array !== false) { 
$mime_type = $imginfo_array['mime']; 
switch($mime_type) { 
case "image/jpeg": 
// your actions go here... 
} 
} 
else { 
echo "This is not a valid image file"; 
} 
新聞熱點
疑難解答