2017-10-01 2 views
0

왜이 이미지와 함께 PHP를 getimagesize 할 수 없습니까?왜이 이미지로 PHP를 getimagesize 할 수 없습니까?

이 이미지에서 나는 PHP를 getimagesize 할 수 있습니다.

<?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를 위해 할 수 있습니까?

+0

왜냐하면 : 사용자 에이전트 차단 ?? 어떻게 원격 액세스에 사용할 수있는 두 번째 리소스를 디버깅 했습니까? – mario

답변

1

웹 사이트가 "hot-linking"을 허용하지 않거나 PHP의 사용자 에이전트를 차단할 수 있습니다. 당신이 디스크에서 같은 첫 이미지를 다운로드 할 경우

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 

가 작동 : 당신이 URL에서 데이터를 가져 오는 시도하면

당신은이 1.1 (403)가 금지 HTTP/ 응답 얻을 것이다 :

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이 모든 이미지에서 작동하지 않습니다. 이미지 자체를 다운로드 할 수 없습니다.

+0

PHP의 사용자 에이전트를 차단하는 사이트에서 이미지를 다운로드하는 방법은 무엇입니까? –

+0

요청하기 전에'ini_set'을 사용할 수 있습니다. [이 답변] (https://stackoverflow.com/questions/8974742/change-user-agent-using-php)을 참조하십시오. –

관련 문제