On Mon, Feb 24, 2014 at 2:42 PM, Mike Miller <mbmiller+l at gmail.com> wrote: > 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: > I don't think that will work. It's been a while since I played around with it, but I think if the actual size and the size you report are different some browser complain that the download might be corrupt. If you have a temp file, you would need to get its size in bytes and then send the Content-Length header. $ 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. You probably want to pass in some sort of download file name too, otherwise users end up with archive.zip, archive(1).zip, archive(2).zip and they're all for different directories. > > > Mike > _______________________________________________ > TCLUG Mailing List - Minneapolis/St. Paul, Minnesota > tclug-list at mn-linux.org > http://mailman.mn-linux.org/mailman/listinfo/tclug-list > -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://mailman.mn-linux.org/pipermail/tclug-list/attachments/20140224/be3562cd/attachment-0001.html>