2014-02-23 2 views
2

URL을 사용하여 외부 소스의 이미지를 검색하고 웹 서버에 저장하고 있습니다. 불행히도 다음 오류가 발생합니다. 스트림을 열지 못했습니다. HTTP 요청이 실패했습니다! HTTP/1.1 500 내부 서버 오류.file_get_contents가 스트림을 열지 못했습니다 : HTTP 요청이 실패했습니다! HTTP/1.1 500 내부 서버 오류

브라우저로 지정된 URL을 방문하면 이미지가 표시되고 유효합니다. URL이 : 나는 500 오류가 발생하는 이유

$opts = array('http'=>array('header' => "User-Agent:Mozilla/5.0 (Windows NT 6.2) AppleWebKit/537.1 (KHTML, like Gecko) Chrome/21.0.1180.75 Safari/537.1\r\n", 'timeout' => "360")); 
$context = stream_context_create($opts);           
$imageString = file_get_contents(urldecode(urlencode($filename)), false, $context);            
$save = file_put_contents(dirname(dirname(__FILE__)) . '/tmp/' . $id . '_' . $sequenceNumber . '.jpg', $imageString); 

사람이 생각이있다 :

http://****.com/00/s/NTgwWDcyNg==/z/7LEAAMXQVT9TCcxx/$_85.JPG 

내가 사용하는 코드?

+0

뭐죠? –

+0

urlencode/urldecode와 함께 500 오류를 준 phpfiddle을 사용하여 다른 이미지 URL을 테스트했는데이를 수정했습니다. phpfiddle에서이 URL을 처리 할 때 호스트가 해결되지 않으면 file_get_contents 앞에 @가 붙습니다. 그러나 @는 무엇을 하는가? – user3009108

+0

http://stackoverflow.com/questions/1032161/what-is-the-use-of-symbol-in-php – miken32

답변

5

다음 대답은 나를 위해 일한 :를 urlencode와 URLDECODE와 PHP file_get_contents 500 Internal Server error

$opts = array('http' => array('header' => "User-Agent:MyAgent/1.0\r\n")); 
$context = stream_context_create($opts); 
$header = file_get_contents('https://www.example.com', FALSE, $context); 
관련 문제