I have lots of zip files on my website that people download.
They are a collection of images. sometimes the zip folders can be up to 600mb each.

If i want to add just one file in to the zip folder it seems to me that I have to upload the whole thing again. (Via FTP - Takes ages)

Does anyone know if it's possible to add files to a zip once it has been uploaded?

I use Dreamweaver CS3 and use Apache webserver running Fedora.

djr33

01-10-2008, 12:54 PM

It's not possible to "change" a file that is on your FTP through FTP.
The one exception would be if you were to resume uploading if it cut off (some FTP clients allow this), but only if it's in a linear format and can just continue from a point in the file.
Adding a new image would change the compression of the zip file. In other words, the entire file will be different (because the compression structure in a zip file is based on minimal data for all parts, so each file in it is compressed related to the others, and the shell holding these would also change).

You can't just add an image to a zip file by any means I've heard of. It might be theoretically possible to add another file to a zip that isn't compressed by just adding the bytes directly, but I don't know of any software that allows this.

So, the answer is basically no.

There is one possibility, though.

You could change the zip file on the server itself, but not through FTP. So, if you were to physically be on that machine, you could unzip the contents, add the image to the folder, and rezip it. Since you probably don't have direct access, no possible.
However, this is possible using PHP. You can open the zip archive and add a file and resave (close) the archive.
The problem, though, is that PHP sometimes has a low memory allocation and you would need to have literally 600mb of RAM used to hold the file while modifying. (It might even need two copies-- the old and the new-- I'm not sure.)
I have also yet to find a reliable zip library for PHP. I've used a couple and they worked most of the time at least on a certain server. Good luck, and trial and error until you find one.

Similarly, there may be some linux shell commands you could use, but I don't know what those would be.

Honestly, just resave the zip (or save it in smaller chunks so it's easier to update later), and just wait for it to upload. By the time you post and wait for an answer, it'll probably be done. I know that's not fun, but it's the simplest way to fix this.

BLiZZaRD

01-10-2008, 10:22 PM

Agreed.

I do know that some servers (Linux) can allow you to un-zip/tar files on the server with Shell Access. If you have those you can poke around for the commands, unzip your files, then rezip including the new pictures and be done.

I am not sure of the space requirements or server load of doing this, and you may even get help from your server host.

You could always ask them, as long as this isn't an everyday thing I don't see why they wouldn't.

djr33

01-10-2008, 10:57 PM

If this isn't an everyday thing, just wait for the upload.
But if it is, then I would look into the shell commands.

It'll probably take a bit of time to figure out, but that's very worth it if you are updating these frequently. It sounds like you may be adding photos on a fairly regular basis.

Also, if you are updating it frequently, one strategy would be to keep a folder of the photos on the server then add images to that (it could even be attached to an upload form). Then have a PHP script (or use shell commands via a different method if you prefer) which you can run to generate a zip from that. Downside is that you'd need space for both the raw and archived data, and there would need to be enough processing power/memory allotted to you (and possibly the PHP script) for large files.

jc_gmk

01-11-2008, 02:21 PM

Thanks guys, some really useful info there!

My server is hosted for me but it's a dedicated server so I have full root access.
I will certainly look in to the shell commands and if i manage to get it working I will post the answer here.

Shotgun Ninja

01-25-2008, 10:55 PM

Have you tried ZLIB? I saw it in the extensions list on the PHP 5.x installer, and it seems like it would work okay... Check it out, at least. It might be worth it.