我有一些pdf文件...我只想将它们作为集合下载,而不是一个一个地下载。 为此,我想压缩所有pdf文件并下载。但我不知道为什么当我在我的代码中更改ZipArchive文件名时,它说的是损坏和损坏。 我的代码如下: -下载由PHP中的多个文件构成的Zip文件
function zipFilesAndDownload($file_names,$archive_file_name,$file_path)
{
$zip = new ZipArchive();
//create the file and throw the error if unsuccessful
if ($zip->open($archive_file_name, ZIPARCHIVE::CREATE | ZIPARCHIVE::OVERWRITE)!==TRUE) {
exit("cannot open <$archive_file_name>\n");
}
//add each files of $file_name array to archive
foreach($file_names as $files)
{
$zip->addFile($file_path.$files,$files);
}
$zip->close();
//then send the headers to foce download the zip file
header("Content-type: application/zip");
header("Content-Disposition: attachment; filename=$archive_file_name");
header("Pragma: no-cache");
header("Expires: 0");
readfile("$archive_file_name");
exit;
}
if($button=="Save as pdf")
{
$file_names = array();
foreach($a as $key=>$as)
{
$file_names[] = $key.'.pdf';
}
}
$archive_file_name='zipped.zip';
$file_path='/resume/';
zipFilesAndDownload($file_names,$archive_file_name,$file_path);
?>
有人能帮我吗?提前致谢。
它的工作正常,但我仍然面临2个问题,1。如果我将archive_file_name的名称更改为上面给出的以外的内容,则会出现“存档已损坏”的错误。我不知道它为什么发生2.如果我有一个zip文件,说2个pdf,然后我再次下载一个只有1个pdf的zip文件,这个文件与以前的不一样。但是当我下载1 pdf的zip文件时,我得到3个pdf文件......我不知道为什么........请帮助我。
你试过了哪个名字?哪一个是好的? – j0k 2012-07-14 17:51:16
我已经尝试过zipper1.zip,它不能正常工作。它只与zipper.zip名称一起工作。 – hatellla 2012-07-14 19:57:26