Link to home
Start Free TrialLog in
Avatar of plr
plrFlag for Russian Federation

asked on

Return "content-type: application/zip" as result.

I create CGI/perl script for downloading resources from my site. After user posts some info (name, e-mail) the script must return "content-type: application/zip" with some predefined file as result.
How can I return this?

P.S. it's runnings under Apache v1.3.2/linix & perl5
Avatar of mouatts
mouatts

The first thing that your CGI must output is an HTTP header.

The actual header that you want will look as follows

print "Content-type: application/x-zip\n\n"

The two /n (newlines) indicate that it is the end of the HTTP header. However I know that at least oone perl CGI library provides its own routines for outputing the mime types and if you are using one of these then you should use these as functions.

HTH
Steve
Avatar of plr

ASKER

Hey! I mean than what must script does after print "content-type...."?
After the http response header comes the response body, for your case, it is probably a zipped file.  Which means that you should read a file in binary mode and then write its contents to stdout.  You can use read() and write() to do this.  It is better to first get the size of the file and output it in the content-length header.
Why not make it easy on yourself and use the following instead of the "Content-type yada-yada" header and the hassle of reading the binary file? Just assign $filename to what they select in your form.  Works well for me...

#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
$filename="whatever.zip";
print "Click <A HREF=\"$filename\"><B>HERE</B></A> to start your download";
exit;

Avatar of plr

ASKER

Sorry, I don't need easy way, I need only what I ask.

ASKER CERTIFIED SOLUTION
Avatar of sdjjm
sdjjm

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of plr

ASKER

Thank you! It works fine.