I have a compressed directory which contains some files and subdirectories. What I want to achieve is to modify the content of the compressed directory and then download the modified zip file, so that the changes are not altered inside the original zip file.
For example, I want to delete a specific file inside the compressed directory and then download the modified zip file, so that the file still exists in the original compressed directory.
Here is my code so far. It works fine, but the problem is that the file is also deleted inside the original compressed directory :
<?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');
?>
How can I achieve the desired functionality?