I need a way to download a lot of files and save them to the file system with PHP. This is for a deployment tool, and I was planning on using a Zip file, since I just call some unzip code and it's simple. However, the ZIP functionality is an extension that not everyone has.
My only other idea right now is to compress everything into one file as Base64 encoded, decode it and write it back out. This isn't ideal (Or is it?). Suggestions?
Zip is really not difficult to parse, if you can follow a rather simple file format specification and are willing to count on the zlib extension to be installed to handle the decompression.
Otherwise, invent your own custom archive file format, it's not hard. It could be something a dead simple as this:
So a very simple archive file might look like
You could of course improve it by storing lengths in binary format (e.g. using
pack
with the 'N' format), adding checksums, and so on. But it was easier to explain this way.base64 just translates a chunk of data into a format that's "safe" to transmit via email, which can then be decode back into its native 8bit format. It doesn't allow multiple files to be archived/compressed into a single file. You could embed multiple seperate base64-encoded files in something like a MIME message, which does allow multiple different attachments. But then you're back to the same problem - not everything will natively handle MIME messages, since that's the domain of email.
Zip is your best choice. There's versions of it available for every major OS under the sun, and is built into the file managers for the big 2 - MacOS and Windows. The other alternatives (rar, 7z, etc..) are far less common and definitely have no chance of out-of-the-box support.