[ back to toc ]

download

Date: 2002/06/06 12:23

Q:
Hello,
Thank you for your time to consider my problem.
How do I force user to download files from my
apache server? I need them can see the "File Download"dialog box which has
"open" and "save as" two choices whenever they download word file or text
file or excel file.
I spent a lot of time and tried to find a solution
by using different header content such as "applicatin/octet-stream", but
still doesn't work.
The test scripts is listed as follows:

#!/usr/bin/perl
use CGI qw(:standard);

$q=new CGI;
$download_type="application/octet-stream";

print $q->header($download_type);
print "<a href=\"tang.doc\">download word file</a><br>";
print $q->a ({-href=>"GSM57.txt"}), "download array text file", "<br>";

All the files to be download should be in the
DocumentRoot dirctory, right?
Do I need to do extra apache server configuration?
How could I do it?

thank you!

A:
>>>
How do I force user to download files from my
apache server?
<<<

Taking it seriously the only way is to put the gun against the head.

"applicatin/octet-stream" -> "application/octet-stream"

ok this is correct in the script.

Your script sends an HTML file along with the Content-Type header:
application/octet-stream You are lucky that the browser displays the HTML
page at all. The header type in your script has nothing to do with the
file you want the client to download. What you need is:

#!/usr/bin/perl
use CGI qw(:standard);

$q=new CGI;

print $q->header(="application/octet-stream");
open(F,"tang.doc");
undef $/;
binmode F;
$q = <F>;
close F;
print $q;

>>>
All the files to be download should be in the
DocumentRoot dirctory, right?
<<<

Not at all. You can put it where you want. The only issue is that the
script that sends it to the browser (and not the HTML file containing the
reference to the file!) can read the file.

>Do I need to do extra apache server configuration?

Not at all.

Regards,
Peter

[ back to toc ]