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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux