PHP에서 URL을 사용하여 일련의 이미지를 가져오고 싶습니다. 나는 file_get_contents
과 curl
을 사용해 보았습니다. 아래는 사용하려고 시도한 코드입니다.URL에서 이미지 저장
401 - Unauthorized : Access is denied due to invalid credentials.
암호는 특수 문자가 있습니다
$image = file_get_contents('http://user:[email protected]/directory/images/image1.jpg');
file_put_contents('D:/images/image1.jpg', $image);
와 두 경우 모두
$url = 'http://server/directory/images/image1.jpg';
$localFilePath = 'D:/images/image1.jpg';
$ch = curl_init ($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_BINARYTRANSFER,1);
curl_setopt($ch, CURLOPT_USERPWD, "user:pwd");
$raw = curl_exec($ch);
curl_close ($ch);
if(file_exists($localFilePath)){
unlink($localFilePath);
}
$fp = fopen($localFilePath,'wb');
fwrite($fp, $raw);
fclose($fp);
, 나는 다음과 같은 오류를 얻고있다. 암호 정책이 허용하지 않는 일반 암호로 변경할 수는 없습니다.
'file_get_contents()'를 사용하는 경우 인증 헤더를 포함하는 특수 스트림 컨텍스트를 만들어야합니다. 곱슬 곱슬 함이 좋을 것입니다. 특수 문자가 무엇입니까? – hek2mgl
특수 문자가 이스케이프됩니까? – DanFromGermany
특수 문자는 밑줄입니다. 확실하지 않은, 어떻게 그것을 탈출. –