I have a ZIP file on my server. I want to create a PHP file, loadZIP.php that will accept a single parameter, and then modify a text file within the ZIP to reflect that parameter.
So, accessing loadZIP.php?param=blue
, will open up the zip file, and replace some text in a text file I specify with 'blue', and allow the user to download this edited zip file.
I've looked over all of the PHP ZIP functions, but I can't find a simple solution. It seems like a relatively easy problem, and I believe I'm over thinking it. Before I go and write some overly complex functions, I was wondering how you'd go about this.
Have you taken a look at PHP5's
ZipArchive
functions?Basically, you can use
ZipArchive::Open()
to open the zip, thenZipArchive::getFromName()
to read the file into memory. Then, modify it, useZipArchive::deleteName()
to remove the old file, useZipArchive::AddFromString()
to write the new contents back to the zip, andZipArchive::close()
:Note ZipArchive was introduced in PHP 5.2.0 (but, ZipArchive is also available as a PECL package).