Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

why my download script won't work? 1

Status
Not open for further replies.

jackjake

Programmer
Apr 15, 2005
8
0
0
US
Can anyone let me know why my download script won't work?
After a user clicks a download link, this script will run, but it does not work:

#!/usr/bin/perl -w

use CGI qw:)standard);

my $q=new CGI;

print $q->header(-type => "text",
-attachment => "/var/
It does popup a download window, but does not give the filename and
type, and the file it downloads is always 0 byte.

also tried this, the download window does show file type, but still
the file downloaded is 0 byte

#!/usr/bin/perl -w

use CGI qw:)standard);

my $q=new CGI;

print $q-header(-type => "application/vnd.ms-excel",
-attachment =>
"/var/
 
You actually have to push the file contents out through your script. Something like so:

Code:
#!/usr/bin/perl -w
 
 use CGI qw(:standard);
 
 my $q=new CGI;
 
 print $q-header(-type => "application/vnd.ms-excel",
            -attachment =>
 "/var/[URL unfurl="true"]www/cgi-bin/jake/project/ex.xls");[/URL]

open (FILE, "/var/[URL unfurl="true"]www/cgi-bin/jake/project/ex.xls")[/URL] or die "File won't open: $!";
binmode FILE;
while ($line = <FILE>)
{
    print $line;
}
close (FILE) or die "Can't close file: $!";

- Rieekan
 
Rieekan, thanks for the help! I got the following error:
Argument "Content-Disposition: attachment; filename="/var/ isn't num
eric in subtraction (-) at play.pl line 7.

got same error even if I changed the file to:
#!/usr/bin/perl -w

use CGI qw:)standard);

my $q=new CGI;

print $q-header(-type => 'text',
-attachment => 'ex.xls');

open (FILE, "ex.xls") or die "File won't open: $!";
binmode FILE;
while ($line = <FILE>)
{
print $line;
}
close (FILE) or die "Can't close file: $!";
 
Your header statement is formatted incorrectly. It should read:

Code:
print $q-[b]>[/b]header(-type => "application/vnd.ms-excel",
                        -attachment =>  "/var/[URL unfurl="true"]www/cgi-bin/jake/project/ex.xls");[/URL]

My mistake too, I had just copied your code when replying. That'll teach me not to read very clearly.

- Rieekan
 
Oh, man! thank you so much! I have to compare the two lines side by side to find my error! sorry for my carelessness.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top