Google Answers Logo
View Question
 
Q: Javascript (?) question - build a zipfile 'on the fly' and send it ( No Answer,   5 Comments )
Question  
Subject: Javascript (?) question - build a zipfile 'on the fly' and send it
Category: Computers > Programming
Asked by: davidfilmer-ga
List Price: $7.50
Posted: 20 Jun 2003 01:01 PDT
Expires: 24 Jun 2003 22:50 PDT
Question ID: 219575
Greetings. I am webmaster for a Boy Scout Troop website
(troop606.com). The site is made up entirely of Perl CGI scripts.  I
host a collection of photo galleries, organized by event (campout,
Court of Honor, etc).

In each gallery, I offer the option to click a link to download all
the photos as a single zipfile.  I presently do this with a simple <a>
tag like this:

   <a href='campout.zip'>Click here to download everything</a>

And the person on the other end gets the usual "save as..." dialouge
box and can save all the photos in one click. This is a great feature
for the Troop, but it means that the disk space required by my photo
galleries is doubled, because I must host the individual jpeg's as
well as the zipfiles. The photo galleries are (by FAR) the biggest
thing on my website, and now I'm doubling their space requirement!

What I would prefer to do is to build the zipfile "on the fly."
Zipfiles build VERY quickly, even for the largest gallery, because I
don't use any zip compression (since jpeg is already compressed).

So, as I envision it, when the person clicks the link the server would
build the zipfile and then (somehow) feed it to the client browser (to
initiate the 'save as' dialouge), and then delete the zipfile once the
transfer is complete. All that, with one click!

OR -- even MUCH, MUCH better -- the server never creates a zipfile
locally, but just redirects the output of the zip command to the
client browser, and the client browser thinks it's downloading a
regular zipfile). That would be IDEAL!

I know how to build the zipfile, but that's about it. But I suspect
that it can be done, and I suspect it's not really that difficult. 
However, if a researcher provides an answer that reflects a level of
complexity that I did not anticipate then I will gladly respond with a
gratuity that would double (or even triple) the (somewhat low) price
of this question.

The server is running on Mandrake Linux 9.1. I'm using Perl (5.8)
system forks to Info-ZIP (2.3) to do archive manipulation.  An answer
wouldn't be of any use unless it can be implemented in this (very
capable and up-to-date) environment.

Thanks for reading, and thanks for helping me develop a great Scouting
resource!
Answer  
There is no answer at this time.

Comments  
Subject: Re: Javascript (?) question - build a zipfile 'on the fly' and send it
From: damiam-ga on 20 Jun 2003 12:29 PDT
 
I haven't tested it, but this perl snippet might do what you want...

#we're transmitting a zip file...
print "Content-type:application/zip\n\n";
#pipe the output from zip
open(ZIP, "zip - <filestozip> |");
#and feed it to the client
while(<ZIP>)
{
    print $_;
}

The downside with piping zip output directly to the client is that it
leaves the zip process open for the entire download, which could
easily bog down a slower server if you had more than a few
simultaneous connections.
Subject: Re: Javascript (?) question - build a zipfile 'on the fly' and send it
From: davidfilmer-ga on 23 Jun 2003 23:08 PDT
 
Thanks for your great suggestion.  Sorry I wasn't able to give it a
try until just now.

Your idea ALMOST works.  Try http://troop606.org/cgi-bin/sendzip.cgi
(which should dynamically send you the same thing as if you clicked on
http://troop606.org/content/gallery/2002-04-15_Boeing_Trip/2002-04-15_Boeing_Trip.zip).

Except when the client gets the "save as..." window, the default
filename is "sendzip.cgi."  If the client overtypes this proposed
filename with something like 'boeing_visit.zip' then it works great,
but most of my target audience is made up of young kids and adults
(including grandparents in the photo gallery) with VERY limited
computer understanding.

OK, I could easily enough set it up so the click would give the
browser a file named 'boeing_visit.zip.cgi' and then try to tell them
to take the '.cgi' off, but THAT'S NOT GOING TO WORK, trust me. These
are great folks every one, God bless 'em, but some won't get it unless
the webserver hands them a file with the correct filename.

Do you have any idea how to force the client browser to see the
filename as something OTHER than yadayadayada.cgi?

Thanks again!
Subject: I figured out a workable MAJOR KLUDGE; damian-ga furnishd the critical bit......
From: davidfilmer-ga on 24 Jun 2003 00:04 PDT
 
Hmmm.  Thinking about the problem some more, I, um, figured out
SOMETHING that would work. I do believe this sets my absolute personal
best record for a MAJOR KLUDGE, and I'd hold this next to the
kludgiest kludge I've ever seen. May Donald Knuth have mercy on me for
what I'm about to type...

OK, I never use uppercase file extensions on my Linux box (and I
sanatize all incoming filenames to lowercase). But I'm not aware of
any zip application (including Linux InfoZIP) that actually gives a
flip whether a zipfile's .zip extension is uppercase or lowercase (or
mixed).  So...

I give Apache a directive like this:

   AddHandler cgi-script .ZIP

and then add insult to injury with a directive like this:

   <Directory /var/www/html/content/gallery>
       AllowOverride All
       Options ExecCGI FollowSymLinks
       <IfModule mod_access.c>
         Order allow,deny
         Allow from all
       </IfModule>
   </Directory>

Now I've told Apache that .ZIP is basically a cgi, and it's OK to run
CGI programs from gallery directories, and it's OK to follow simlinks
(a security auditor would be red in the face about now).  I `httpd
reload` and...

In a gallery directory I set up a simlink similar to this:

   2002-02-15_Court_of_Honor.ZIP -> /var/www/cgi-bin/sendzip.cgi

See, toldya it was a major kludge!  But I'll be darned if it don't
work in my little test!

The kludge is not implemented on the site yet, but I believe this will
fit the bill (of course, I'm always open to less kludgy alternatives).

damiam-ga - your comment provided me the critical bit of information I
needed to make this all happen, and I consider your comment to be a
satisfactory answer to my question.  Would you kindly close this as
"answered" so you may receive credit?

Thanks!!!!!!
Subject: Re: Javascript (?) question - build a zipfile 'on the fly' and send it
From: hammer-ga on 24 Jun 2003 12:28 PDT
 
Hi Davidfilmer.

Damiam-ga is not a Researcher, so he/she cannot "answer" your
question. You can tell a Researcher by the name being a clickable
link. Since a Commenter has provided the information you need, you can
expire your question and go enjoy your free answer!

- Hammer
Subject: Re: Javascript (?) question - build a zipfile 'on the fly' and send it
From: davidfilmer-ga on 24 Jun 2003 22:50 PDT
 
Oh, I see. Thanks for clarifying that for me.

And thank you Damian-ga for your timely assistance!

Important Disclaimer: Answers and comments provided on Google Answers are general information, and are not intended to substitute for informed professional medical, psychiatric, psychological, tax, legal, investment, accounting, or other professional advice. Google does not endorse, and expressly disclaims liability for any product, manufacturer, distributor, service or service provider mentioned or any opinion expressed in answers or comments. Please read carefully the Google Answers Terms of Service.

If you feel that you have found inappropriate content, please let us know by emailing us at answers-support@google.com with the question ID listed above. Thank you.
Search Google Answers for
Google Answers  


Google Home - Answers FAQ - Terms of Service - Privacy Policy