为什么我不能在此图像中使用getimagesize php



为什么我不能将getimagesize php与此图像一起使用?

对于此图像,我可以得到getimagesize php,工作良好。

<?PHP
        $source = "https://i.pinimg.com/736x/da/7a/19/da7a19a0c3daabe579ecca21d1ae32c3--felt-wool-felting-projects.jpg";
        $dimension = getimagesize($source);
        $width = $dimension[0];
        $height = $dimension[1];
        echo $width;
        echo "<BR>";
        echo $height;
?>

但是,对于此图像,为什么我无法获得getimagesize php?

<?PHP
        $source = "https://shorebread.com/wp-content/uploads/2016/07/kitty-cat-reaching_138482216-2000x500.jpg";
        $dimension = getimagesize($source);
        $width = $dimension[0];
        $height = $dimension[1];
        echo $width;
        echo "<BR>";
        echo $height;
?>

我该如何在每个图像上使用getimagesize php?

可能是网站不允许"热链接"或阻止PHP的用户代理。

如果您尝试从URL获取数据,您将获得 http/1.1 403 forbidden forbidden 响应:

php > $dimension = getimagesize($source);
PHP Warning:  getimagesize(https://shorebread.com/wp-content/uploads/2016/07/kitty-cat-reaching_138482216-2000x500.jpg):        
 failed to open stream: HTTP request failed! HTTP/1.1 403 Forbidden
 in php shell code on line 1

如果首先下载图像,然后从磁盘上执行同样的操作:

php > $dimension = getimagesize("kitty-cat-reaching_138482216-2000x500.jpg");
php > print_r($dimension);
Array
(
    [0] => 2000
    [1] => 500
    [2] => 2
    [3] => width="2000" height="500"
    [bits] => 8
    [channels] => 3
    [mime] => image/jpeg
)

因此,并非getimagesize在所有图像上都无法使用。它无法下载图像本身。

最新更新