私はいくつかの PDF ファイルを持っています...それらを 1 つずつではなく、コレクションとしてダウンロードしたいのです。そのために、すべての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 つの問題に直面しています。archive_file_name の名前を上記以外の名前に変更すると、アーカイブが破損しているというエラーが発生します。2.たとえば、2つのpdfのzipファイルを取得した場合、以前のものとは異なる1つのpdfのみのzipを再度ダウンロードします。しかし、1 つの pdf の zip をダウンロードしているときに、3 つの pdf を取得しています......理由がわかりません.......助けてください。