plr
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
How can I return this?
P.S. it's runnings under Apache v1.3.2/linix & perl5
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;
#!/usr/local/bin/perl
print "Content-type: text/html\n\n";
$filename="whatever.zip";
print "Click <A HREF=\"$filename\"><B>HERE
exit;
ASKER
Sorry, I don't need easy way, I need only what I ask.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you! It works fine.
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