2013-02-06 2 views
0

file_get_contents()가 URL에서 이미지를 가져 와서 zip 파일로 출력하도록하려면 어떻게해야합니까? 예컨대url의 이미지가있는 file_get_contents()를 우편 번호로 저장하십시오.

http://example.com/image1.jpg 
http://example.com/image1.jpg 
http://example.com/image1.jpg 

때 지금은 .ZIP에이 문자열을 변환 할 수있는 방법, 문자열에 저장할 수 있습니다 file_get_contents로 검색 할 수 있습니다.

여기서 인코딩 된 json에서 이미지 URL을 추출해야합니다. 당신이 시도

copy('http://example.com/image1.jpg', '_tmp/image1.jpg') 
copy('http://example.com/image2.jpg', '_tmp/image2.jpg') 
... 
zip(_tmp); 
delete(_tmp); 
+5

[당신은 시도 무엇?] (http://whathaveyoutried.com) –

답변

0

<?php 

$files = array(
     'http://flask.pocoo.org/static/logo/flask.png', 
     'http://flask.pocoo.org/static/logo/flask.pdf'); 

function create_zip(array $files, $destination='img.zip'){ 
    $zip = new ZipArchive();  
    $zip->open($destination, ZIPARCHIVE::CREATE); 
    foreach($files as $file){ 
     print $file; 
     if(copy($file, basename($file))){ 
      print 'Successfully Copied '; 
      if(file_exists(basename($file))){ 
       $zip->addFile(basename($file)); 
      } 
     }else{ 
      print 'Failed to copy !!!'; 
     } 
    } 
    $zip->close(); 
} 

create_zip($files, 'testing.zip'); 
+0

니스 접근, 나는 모든이 작업을 수행해야합니다으로 사용자가 다운로드 중입니다. 그래서 기본적인 질문은 얼마나 많은 부하가 서버에서 발생 하는가? –

+0

이 경우 반드시 'list of required files' =>'zip archive name'이라는 연관성을 가진 캐시를 만들어야 매번 다시 생성하지 않고 우편을 배달 할 수 있습니다. 이제는 모두 [imagesSize] x [imagesNumber] => 파일 복사 및 우편 작업에 따라 다릅니다. [folderDelete]는 거의 순간적이어야합니다 (10-20 개 이상의 파일이없는 경우). – vectorialpx

+0

여기에 LIL 문제가 있습니다.이 copy() 함수가 작동하지 않습니다. –

0

을 시도 할 수

+0

두 파일 모두 복사에 실패했습니다. –

+0

복사하려는 디렉토리에 대한 쓰기 권한이 있습니까 ??? – Redian

+0

예 내 폴더 "_tmp"의 길이는 777입니다. –

관련 문제