Search code examples
phpencodinggetimagesize

getimagesize & non-Latin characters


When i try to get image size from url

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

I got error

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

Solution

  • It works if you urlencode the filename:

    <?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";
    }
    ?>