下面來創建壓縮文件生成多個文件的ZIP代碼:無法在笨
<?php
$file1 = 'D:/xampp/htdocs/pdf/pdffiles/14816393105-annexc-form.pdf';
$file2 = 'D:/xampp/htdocs/pdf/pdffiles/14816393105-resident-form.pdf'
$files = array($file1,$file2);
$zipname = time().'-file.zip';
$zip = new ZipArchive;
$zip->open($zipname, ZipArchive::CREATE);
foreach ($files as $file) {
$zip->addFile($file);
}
$zip->close();
header('Content-Type: application/zip');
header('Content-disposition: attachment; filename='.$zipname);
header('Content-Length: ' . filesize($zipname));
readfile($zipname);
?>
此代碼創建的zip文件,但它已損壞。
編輯:
zip file is created but if i extract it then it is from the D:/ drive. Means zip file contains this:
XAMPP \ htdocs中\ PD˚F\ pdffiles \ file1.pdf
1 - 服務器上的文件(下載前)是否也損壞? 2 - 如果在'addFile'方法中添加第二個參數(文件名),它會工作嗎? –
用文本編輯器打開文件,並檢查頂部是否有空行。如果是這樣,它是否正常化,如果你刪除它們?在這種情況下,檢查你的php文件,看看它們返回空行的位置。 –
@ rap-2-h不,它沒有損壞。 2 - 如果在addFile方法中添加第二個參數(文件名),它會工作嗎? - 意味着? –