[英]PHP ZipArchive large ExtractTo with folders
我在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
ZipArchive將ExtractTo限制為65535個文件,並且無法進行偏移。
因此,發現BTW的最佳解決方法是使用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
它為我工作..! 因為我們的應用程序之一在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 Security組下,使用此命令可能會增加風險。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.