我試圖獲取MIME類型的配置文件圖片格式爲user_id.jpg或gif或png,我嘗試過使用此代碼,但它不起作用。獲取MIME類型的文件
function detectFileMimeType($filename='')
{
$filename = escapeshellcmd($filename);
$command = "file -b --mime-type -m /usr/share/misc/magic {$filename}";
$mimeType = shell_exec($command);
return trim($mimeType);
}
function get_avatar($image, $user_id, $account)
{
$imgurl ="http://mypage/files/pictures/picture-" . ($user_id, $mimeType) . ".jpg";
if (!is_imgurl_good($imgurl)) {
$imgurl = "http://mypage/sites/all/themes/simple_custom/user.png";
}
return $imgurl;
}
您是否考慮過[爲此設計的功能](http://php.net/manual/en/ref.fileinfo.php)? –
我從您提供的頁面中獲取了該代碼。 – user123
您從已棄用的'mime_content_type()'頁面中找到它。 –