【发布时间】:2017-08-04 15:10:57
【问题描述】:
我有一个包含一些文件和子目录的压缩目录。我想要实现的是修改压缩目录的内容,然后下载修改后的zip文件,这样在原来的zip文件里面就不会改动了。
例如,我想删除压缩目录中的特定文件,然后下载修改后的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');
?>
如何实现所需的功能?
【问题讨论】:
标签: php file download directory zip