Re: Zip files: generate text file in archive on the fly

From: Date: Mon, 18 Oct 2010 00:22:49 +0000
Subject: Re: Zip files: generate text file in archive on the fly
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-308776@lists.php.net to get a copy of this message
On 10-10-17 03:55 PM, Dotan Cohen wrote:
I need to provide a download of a zip archive containing three files. This is fairly straightforward in PHP so long as one is working with files that already exist. However, I need to customise one of the files (a simple text file) with the user name and other info before zipping. I see no mention of this in the fine manual, and even googling has led me nowhere. Ideas? Am I missing something obvious? Thanks!
The solution to this seems to be as simple as grabbing the contents of the file using ZipArchive::getFromName (or equivalent), deleting that file in the archive, modifying the contents, then writing the file using ZipArchive::addFromString. Were ZipArchive::getStream able to handle write operations, I imagine you could modify it this way, but reading the file in for modification is much less issue-laden. I haven't tested it, but you could also simply try using ZipArchive::addFromString without deleting the file first. It may just overwrite the file. Thanks, Justin Martin

« previous php.general (#308776) next »