2013-03-19 1 views
0

나는이 URL을 가지고 있습니다. www.example.com/1.png. 다음과 같이 루프를 실행하고 싶습니다.이미지가있는 경우 URL에서 이미지 다운로드

for ($i=0; $i<=10; $i++){ 
$url = 'www.example.com/'.$i.'.png'; 
} 

이제 10x URL이 있습니다. 10 개의 URL 중 7 개가 이미지이고 나머지 3 개는 사용할 수 없습니다. 나는 각각의 URL에서 이미지를 다운로드하고 싶습니다. 그리고 URL이 존재하지 않는다면 아무 것도 다운로드하지 않을 것입니다.

는 Heres는 같은 일을하지만 난 생각보다 basicly 설명했다

www.example.com/1.png --- url exists, so i download the image and save it in my folder. 
www.example.com/2.png --- url exists, so i download the image and save it in my folder. 
www.example.com/3.png --- url doesnt exist, so i dont download anything 
www.example.com/4.png --- url exists, so i download the image and save it in my folder. 
www.example.com/5.png --- url exists, so i download the image and save it in my folder. 
www.example.com/6.png --- url exists, so i download the image and save it in my folder. 
www.example.com/7.png --- url doesnt exist, so i dont download anything 
www.example.com/8.png --- url exists, so i download the image and save it in my folder. 
www.example.com/9.png --- url exists, so i download the image and save it in my folder. 
www.example.com/10.png --- url doesnt exist, so i dont download anything 

죄송합니다 나쁜 영어, 어떤 제안을 내가이 문제를 해결할 수있는 방법?

+1

어디에서 문제가 발생합니까? 너 뭐 해봤 니? 파일 저장 기능을 모른다면 file_get_content()와 file_put_content()를 PHP 매뉴얼에서 찾으십시오. – aleation

+0

'file_get_content()와 file_put_content()' – Edgar

+0

감사합니다. 당신이 이미지를 얻는다면, 그렇지 않으면 그렇지 않을 것입니다. – deceze

답변

0

헤더에서 404 오류를 확인할 수 있습니다. 확인할 수있는 HTTP 응답 헤더를 포함하는 $http_response_header 변수를 생성 할 file_get_contents()와 이미지를 다운로드

$file_headers = @get_headers($url); 
if($file_headers[0] == 'HTTP/1.1 404 Not Found') { 
    //Does not exist 
} 
else 
{ 
    //Exists, so put download code here 
} 
+0

고마워, 내가 원한 것 같아. – Edgar

관련 문제