2012-09-22 61 views
-1

我遇到ZipArchive extractTo的問題。PHP ZipArchive大ExtractTo與文件夾

我有一個+ 300Mb的ZIP文件,每個文件夾中有100個文件夾和+ 3k個XML文件。當我開始這個過程時,它會運行到20個文件夾和內部檔案並停止工作。

這是我的解壓功能...

public function unzip_files($zipfile, $parent_folder) 
{ 
    ini_set('memory_limit', '512M'); 
    set_time_limit(0);  

    $zip = new ZipArchive; 
    $res = $zip->open($zipfile); 

    if($res === true) 
    { 
     if($zip->extractTo(HCAT_UPLOADS . $parent_folder)); 
     { 
      $zip->close(); 

      print '<strong>'. basename($zipfile) .'</strong> '. __('unziped correctly', self::$ltd) .'.<br />'; 

      return true; 
     } 
     else 
     { 
      print __('Failed to unzip', self::$ltd) .' <strong>'. basename($zipfile) .'</strong>.<br />'; 

      return false; 
     } 
    } 
    else 
    { 
     print __('Failed to unzip', self::$ltd) .' <strong>'. basename($zipfile) .'</strong>.<br />'; 

     return false; 
    } 
} 

我怎麼能解壓縮所有文件夾?任何提示? :)

謝謝!
R

回答

2

ZipArchive將ExtractTo限制爲65535個文件,並且無法執行偏移量。

所以,順便說一句發現最好的解決方法是使用shell命令:

public function unzip_files($zipfile, $parent_folder) 
{ 
    $disableds = explode(', ', ini_get('disable_functions')); 

    if(!in_array('exec', $disableds)) 
    { 
     exec("unzip -o $zipfile -x -d $parent_folder"); 

     print '<strong>'. basename($zipfile) .'</strong> '. __('unziped correctly', self::$ltd) .'.<br />'; 
    } 
} 

最好的!
[R

+0

它不僅僅是ExtractTo - PHP 5.3.3似乎有一個內部限制,ZipArchive無法解決超過65k的文件。 – Nick

0

它爲我.. !!,因爲我們的一個應用程序運行在PHP 5.3 - extractTo(),它不允許我們上傳超過65KB的ZIP文件。

exec("unzip -o $zipFileName -x -d $uploadedPath");

例子:

$zip_obj = new ZipArchive(); 
$zip_obj_data = $zip_obj->open($zipFileName); 
if ($zip_obj_data === true) { 
    #$zip_obj->extractTo($uploaded_path); 
    #$zip_obj->close(); 
    $disableds = explode(', ', ini_get('disable_functions')); 
    if(!in_array('exec', $disableds)) 
    { 
     $zipfile = $zipFileName; 
     exec("unzip -o $zipfile -x -d $uploaded_path"); 
    } 
    unlink($zipFileName); 

}  

注:Exec命令沒有下PHP安全組來了,你贏了風險使用此命令。