[英]PHP ZipArchive large ExtractTo with folders
I'm having an issue with ZipArchive extractTo. 我在ZipArchive extractTo时遇到问题。
I've a +300Mb ZIP file, with 100 folders and +3k XML files in each. 我有一个+ 300Mb的ZIP文件,每个文件中有100个文件夹和+ 3k XML文件。 When I start the process, it runs until 20 folders and the inside archives and stops working.
当我开始该过程时,它将一直运行到20个文件夹和内部归档文件停止工作。
This is my unzip function... 这是我的解压缩功能...
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;
}
}
How can I unzip all the folders? 如何解压缩所有文件夹? Any hint?
有什么提示吗? :)
:)
Thanks! 谢谢!
R [R
ZipArchive limits ExtractTo to 65535 files and there's no way to do an offset. ZipArchive将ExtractTo限制为65535个文件,并且无法进行偏移。
So, best workaround found BTW is to use shell commands: 因此,发现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 />';
}
}
Best! 最好!
R [R
It worked for me..!! 它为我工作..! because one of our application is running in PHP 5.3 -
extractTo()
which doesn't allow us to upload ZIP files more then 65KB. 因为我们的应用程序之一在PHP 5.3中运行
extractTo()
,不允许我们上传超过65KB的ZIP文件。
exec("unzip -o $zipFileName -x -d $uploadedPath");
Example: 例:
$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);
}
Note : 'exec' command is not coming under PHP Security group, using this command in your won risk. 注意:'exec'命令不在PHP Security组下,使用此命令可能会增加风险。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.