2011-03-08 5 views
7

PHP에서 파일을 압축 할 때 약간의 문제가 발생했습니다. 나는 파일 배열을 압축하는 함수를 가지고있다.이 파일들은 모두 다른 디렉토리에있다.PHP에서 파일 압축시 디렉토리 구조 제거

폴더/Folder2 폴더/file1.jpg
폴더/file2.jpg
폴더/Folder2 폴더 : 파일의 구조가 같다 우편을

function create_zip($files = array(),$destination = '',$overwrite = false,$add_to_db=true) { 
    print_r($files); 
     $zip = new ZipArchive(); 
     if($zip->open($destination,$overwrite ? ZIPARCHIVE::OVERWRITE : ZIPARCHIVE::CREATE) !== true) { 
      return false; 
     } 
     for($i=0;$i < count($files); $i++) { 
      //echo $files[$i].'<br>'; 
      $zip->addFile($files[$i],$files[$i]); 
     } 



     $zip->close(); 

     if(file_exists($destination)) { 
     // echo("Success"); 
     if($add_to_db == true) { add_file($destination); } 

      return true; 

     } else { 
     //echo("Failed"); 
      return false; 
     } 
    } 

때 사용자의 다운로드 및 추출 :이 기능은 같은 보이는 /folder3/file3.jpg

제 질문은 PHP가 모든 파일을 zip 루트에 놓고 주어진 구조를 무시하도록하는 것입니다. 이렇게 추출 된 파일과 같습니다

/file1.jpg
/file2.jpg
/file3.jpg

그때 폴더에있는 모든 파일을 이동 한 생각과 수있는 유일한 솔루션 이 폴더를 압축하지만, 이것은 과도한 것처럼 보입니다.

답변