0
我有一個包含一些文件和子目錄的壓縮目錄。我想要實現的是修改壓縮目錄的內容,然後下載修改後的zip文件,以便在原始zip文件內部不會更改這些更改。如何修改和下載壓縮目錄而不更改PHP中原始文件的更改?
例如,我想刪除壓縮目錄內的特定文件,然後下載修改後的zip文件,以便該文件仍然存在於原始壓縮目錄中。
這是我的代碼到目前爲止。它工作正常,但問題是,該文件還原來壓縮目錄中刪除:
<?php
$directoryPath = '/Users/Shared/SampleDirectory.zip';
$fileToDelete = 'SampleDirectory/samplefile.txt';
$zip = new ZipArchive();
if ($zip->open($directoryPath) === true) {
$zip->deleteName($fileToDelete);
$zip->close();
}
header('Content-Description: File Transfer');
header('Content-Type: application/zip');
header('Content-Disposition: attachment; filename="' . basename('SampleDirectory.zip') . '"');
header('Content-Length: ' . filesize('SampleDirectory.zip'));;
readfile('SampleDirectory.zip');
?>
我如何能實現所需的功能?