They may be using a redirect (meta tag) to redirect to the download script.
| SitePoint Sponsor |
They may be using a redirect (meta tag) to redirect to the download script.
You can create a page that says something like "your download will begin shortly. If your download doesn't start click here" (include a link to the script) and then refresh the page by pointing it to the script and passing the download params. You can refresh using the following methods:
A meta-tag
JavascriptCode:<META HTTP-EQUIV="Refresh" CONTENT="10;URL=/cgi-bin/download.cgi?ID=file.jpg">
I, personally, like to include both.Code:<SCRIPT TYPE="text/javascript" LANGUAGE="JavaScript"> <!-- function redirect () { setTimeout("go_now()",5000); } function go_now () { window.location.href = "/cgi-bin/download.cgi?ID=file.jpg"; } //--> </SCRIPT>
On my system, I needed to add:
binmode DLFILE;
immediately after:
open(DLFILE, "$files_location/$ID")...
otherwise files were not downloaded in their entirety... bytes were dropped and the downloaded files didn't open correctly.
is there anyway to add a download counter that will get displayed against each download
I try to download *.doc file. I get only first 590 bytes, I tried
...
print "Content-Type:application/x-download\n";
print "Content-Length: 10000 \n"
...
didnot help, "binmode DLFILE" too
No, the entire script don't work,
i can only get an error-message "The server can't open the file: No such file or directory"
I must be missing something because every time I try running this all I get is the print messages on my page, and the file which I'm trying to download (small text file) simply displaying fully on my page. Where is the save as box?
The save-as box should be initiated from these lines in the file:
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
If they are not, have you changed anything in the script?
There is a more robust article and code discussing the same topic here:
http://bytes.com/topic/perl/insights...ad-script-perl
I cannot seem to get the script to work, yet I copied it very carefully and have re-checked it several times. I get the following error:
Software error:
syntax error at download.cgi line 23, near ")
print"
Execution of download.cgi aborted due to compilation errors.
What have I done incorrectly... following is my final script:
#!/usr/bin/perl
use CGI ':standard';
use CGI::Carp qw(fatalsToBrowser);
my $files_location;
my $ID;
my @fileholder;
$files_location = "think-lat/public_html/upload";
$ID = param('ID');
if ($ID eq '') {
print "Content-type: text/html\n\n";
print "You must specify a file to download.";
} else {
open(DLFILE, "<$files_location/$ID") || Error('open', 'file');
@fileholder = <DLFILE>;
close (DLFILE) || Error ('close', 'file');
print "Content-Type:application/x-download\n";
print "Content-Disposition:attachment;filename=$ID\n\n";
print @fileholder
} sub Error {
print "Content-type: text/html\n\n";
print "The server can't $_[0] the $_[1]: $! \n";
exit;
}
Bookmarks