创建zip存档会使多个文件附加不可预测的字符串

时间:2011-09-09 18:41:43

标签: php zip archive

我正在尝试创建一个PDf下载程序,用户可以在其中选择几个文件,然后下载他们所选内容的zip。我让它在我的个人服务器上工作,但在生产服务器上我得到一个奇怪的错误。生成zip文件,但它附加了一串数字,例如;

zipfile.zip.a08752,zipfile.zip.b08752

Weirder仍然,如果我删除了结尾的字符串并下载文件,它会正确扩展。

我在这个主题PHP Zip Archive sporadically creating multiple files中读到,文件试图多次关闭,失败和重试是一个问题。

下面是我的zip函数的代码,虽然我怀疑它与配置有关     

 function buildZip($params){
    /* Generate unique Id  */
$downloadid = uniqid();

/* Pull in the order.xml */ if(!empty($_REQUEST['downloadlink'])){ if( $params->usexml == true){ $xml = @simplexml_load_file($params->pdfolder.'/order.xml'); $order = $xml->children(); }else{ $order = $params->files; } /* Create the new Zip */ $zip = new ZipArchive(); if ($zip->open($params->zipname.'version'.$downloadid.'.zip', ZIPARCHIVE::CREATE) !== TRUE) { die ("Could not open archive"); } /* Generate the download link to output further down the page */ global $downloadLink; $downloadLink = $params->zipname.'version'.$downloadid.'.zip'; /* Make selected variable available to build the listSelection function */ global $selected; $selected = array(); $i = 0; foreach($order as $el){ if (isset($_POST[$i]) == true){ //generate list of selected PDF's array_push($selected, $el->name); //grab selected pdf's and zip them. echo $zip->addFile($params->pdfolder.'/'.$el->link); $zip->addFile($params->pdfolder.'/'.$el->link) or die ("ERROR: Could not add file: pdf'.$i.'.html"); } $i++; } $zip->close(); } } <code>

对于Clarity,我正在引入一个名为order.xml的XML列表来引入可能的文件数组。

2 个答案:

答案 0 :(得分:0)

在压缩完成后尝试修剪奇怪的数字串

答案 1 :(得分:0)

我遇到了同样的问题。发生这种情况是因为无法创建zip文件。它失败了,因为你的文件太大了。要解决这个问题,我必须创建多个较小的zip文件。我希望这会有所帮助。