是否可以调整此功能,以便它也适用于本地文件路径?
$ meta包含以下内容: Array([wrapper_type] => plainfile [stream_type] => STDIO [mode] => rb [unread_bytes] => 0 [seekable] => 1 [uri] => C:\ imgs \ 232434。 jpg [timed_out] => [已阻止] => 1 [eof] =>)
$ meta [“wrapper_data”]不存在。
function isImage($url)
{
$params = array('http' => array(
'method' => 'HEAD'
));
$ctx = stream_context_create($params);
$fp = @fopen($url, 'rb', false, $ctx);
if (!$fp)
return false; // Problem with url
$meta = stream_get_meta_data($fp);
if ($meta === false)
{
fclose($fp);
return false; // Problem reading data from url
}
$wrapper_data = $meta["wrapper_data"];
if(is_array($wrapper_data)){
foreach(array_keys($wrapper_data) as $hh){
if (substr($wrapper_data[$hh], 0, 19) == "Content-Type: image") // strlen("Content-Type: image") == 19
{
fclose($fp);
return true;
}
}
}
fclose($fp);
return false;
}