2017-02-08 3 views
0

나는 파트너 웹 사이트에서 이미지를 다운로드하는 방법을 php에서 스크립트를 가지고 있습니다. 파트너가 자신의 웹 사이트에 암호를 설정했기 때문에 문제가 cURL 링크에서 이미지 가져 오기

function getimg($url) { 
 
    $headers[] = 'Accept: image/gif, image/x-bitmap, image/jpeg, image/pjpeg'; 
 
    $headers[] = 'Connection: Keep-Alive'; 
 
    $headers[] = 'Content-type: application/x-www-form-urlencoded;charset=UTF-8'; 
 
    $user_agent = 'php'; 
 
    $process = curl_init($url); 
 
\t curl_setopt($process, CURLOPT_USERPWD, "username:password"); 
 
\t curl_setopt($process, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); 
 
    curl_setopt($process, CURLOPT_HTTPHEADER, $headers); 
 
    curl_setopt($process, CURLOPT_HEADER, 0); 
 
    curl_setopt($process, CURLOPT_USERAGENT, $user_agent); 
 
    curl_setopt($process, CURLOPT_TIMEOUT, 30); 
 
    curl_setopt($process, CURLOPT_RETURNTRANSFER, 1); 
 
    curl_setopt($process, CURLOPT_FOLLOWLOCATION, 1); 
 
    $return = curl_exec($process); 
 
    curl_close($process); 
 
    return $return; 
 
}

처럼

스크립트 보인다. 나는 컬의 사용자와 암호를 넣어하지만 작동하지

www.importatorarticolecopii.ro/feeds/general_feed2.php 웹 사이트 URL은

+0

의 내용을 확인하기 위해 오류를 잡으려고을 여기에 올린거야? 아마 좋은 생각이 아닙니다! 오, 그래, 그것은 완전히 있었다. 당신은 지금 그것을 바꿀 필요가있다! –

+0

사이트가 비밀이 아닙니다 .--) 내 파트 네트의 보안 방법 일뿐입니다. –

+0

해당 URL 또는 이미지를 가리키는 URL을 사용하고 있습니까? 이미지 유형 만 허용하기 때문에 작동하지 않을 수 있지만 해당 URL은 이미지가 아닙니다. –

답변

0

귀하의 코드는 괜찮 도움이 필요 ...입니다 주어진 URL에서 문제가 발생했습니다. 위의 URL이 너무 느리고 서버의 최대 실행 시간을 초과하지 않으려 고하여 시간이 초과되었습니다.

curl_setopt($process, CURLOPT_TIMEOUT, 60); 

및 예를 들어, 사용자 에이전트 사용

$user_agent = 'Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.7.12) Gecko/2php0050915 Firefox/1.0.7)'; 

와 미래에

방금 ​​진짜 비밀이 아니었다 문제

if(curl_error($process)) 
{ 
echo 'error:' . curl_error($process); 
} 
관련 문제