【发布时间】:2012-07-14 17:39:15
【问题描述】:
我有一些 pdf 文件...我只想将它们作为一个集合下载,而不是一个一个地下载。 为此,我正在尝试压缩所有 pdf 文件并下载。但我不知道为什么在我的代码中更改 ZipArchive 文件名时,它说已损坏和损坏。 我的代码如下:-
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 的名称更改为上面给出的名称以外的名称,我会收到Archive 已损坏的错误消息。我不知道为什么会这样 2.如果我有一个 zip 文件,比如说 2 个 pdf,然后我再次下载一个只有 1 个 pdf 的 zip,这与之前的不一样。但是当我下载 1 个 pdf 的 zip 时,我得到了 3 个 pdf ......我不知道为什么......请帮帮我。
【问题讨论】:
-
你试过哪个名字?哪个好?
-
我已经尝试过 zipper1.zip,但它不起作用。它只使用 zipper.zip 名称。