getimagesize&非拉丁字符

时间:2017-07-30 19:06:38

标签: php encoding getimagesize

当我尝试从网址获取图片大小时

getimagesize('https://example.com/storage/image图片20170214003852.jpg')

我收到了错误

PHP Warning:  getimagesize(https://example.com/storage/QQ\xe5\x9b\xbe\xe7\x89\x8720170214003852.jpg): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found

1 个答案:

答案 0 :(得分:0)

如果你对文件名进行了urlencode,它就可以了:

<?php
$external_link = 'https://example.com/storage/'.urlencode('image图片20170214003852.jpg');
//$external_link = 'https://nikonrumors.com/wp-content/uploads/2014/03/Nikon-1-V3-sample-photo.jpg';
if (list($width, $height, $type, $attr) = @getimagesize($external_link)) {
  echo "Width=".$width. ', '."Height=".$height;
} else {
    echo  "image does not exist";
}
?>