On Mon, 24 Feb 2014, Michael Moore wrote:

>>> This reminds me to ask about something I've been thinking of doing 
>>> with photos on web pages and Apache cgi-bin.  I have photos on web 
>>> pages with this kind of layout:
>>>
>>
>> http://genetsim.org/Seoul/20100605_Seoul/
>>
>> I wrote scripts that compile pages from a few basic elements -- a 
>> collection of image files in a directory, one file with captions, 
>> another file with intro info, another with title.
>>
>> What I'd like to do is add a link that allows the user to click on it 
>> and download the whole works in a .zip file.  I think the zip file can 
>> be written on the fly instead of storing a bunch of .zip files on the 
>> web server, doubling the space used by photos.
>>
>> Have any of you done something like this using cgi-bin?  It seems 
>> doable but it has been awhile since I've done anything like this.
>
>
> I like to make a temp file and send that so that I can indicate the file 
> size to the user. If you don't indicate a file size the progress bar in 
> their download manager just goes back and forth.
>
> However, if you want to just send a zip file which is created on the 
> fly, you can do something as simple as this:
>
> I save and tried this as a CGI script and it worked. The '-' tells zip 
> to send the zip file to stdout, which in a CGI scenario means to send it 
> to the browser.
>
>
>
> #!/bin/bash
>
> echo "Content-type: application/octet-stream"
> echo "Content-Disposition: attachment; filename='mydownload.zip'"
> echo  ""
>
> zip -0 - /var/www/html/ziptest/*


Thanks for the tip, Michael.  I like the idea of sending a file size.  Do 
you think it would be OK to use the approximate file size I obain using 
this command:

$ du -sb "$DIR" | awk '{print $1}'

That number is usually about 0.5% smaller than the .zip file size.  How do 
you report the filesize?

On the other hand, making a temp file isn't a big deal.  I just don't want 
to store all the .zip files, one per directory.

I guess I need to write the script so that it takes the directory name 
(with path) as an argument.

Mike