复制代码 代码如下:
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";
}
新闻热点
疑难解答