1) The files don't download entirely :)
2) The filename presented in the browser "save-as" dialogue box is the
name of
of my script and not of the file itself.
Concentrating on the first, more serious, problem, here is my code
fragment:
# send the file
my $buffer;
open(dlfile); # $dlfile points to file path
print "Content-type: $mt\n\n"; # $mt is set to mime type
while (read(dlfile, $buffer, 1024)) {
print $buffer;
}
close(dlfile);
These files download okay when I point the web browser directly at them,
as in:
http://www.server.com/filename.Z
(in other words, the server does all the work) but since my objective is
to have
them hidden from web view, the perl script is used to pass them through
the web
server back to the client. But the files, which are binary, truncate at
various places.
Has anyone done this sort of thing with large (>1 meg) binary files? It
works okay
with small ascii files. Also, any hints on the (minor) problem number 2?
Tom Allocco
Ormont Interactive, Inc.
t...@ormont.com
: 2) The filename presented in the browser "save-as" dialogue box is the
: name of of my script and not of the file itself.
ANSWER: href="/cgi-bin/scriptname/filename.here"
: Concentrating on the first, more serious, problem, here is my code
: fragment:
: # send the file
: my $buffer;
: open(dlfile); # $dlfile points to file path
ANSWER: just open the file and output it's contents to STDOUT.
open(OUTFILE, "/path/file")
|| die "Cannot open file!\n";
while(<OUTFILE>) {
print $_;
}
close(OUTFILE);
This works for all sized files I've tried it with. BTW, the mime type
should be application/octet-stream.
HTH
Nate
n...@nfic.com
Maybe try setting $| = 1;
> 2) The filename presented in the browser "save-as" dialogue box is the
> name of my script and not of the file itself.
Here is an example.
#! /usr/local/bin/perl
#http://www.engr.iupui.edu/~dbewley/perl/download.pl
$| =1;
print "Content-type: application/x-gzip\n";
print "Content-Disposition: attachment; filename=dale-perl.tar.gz\n";
print "Content-Description: Dale Bewley's perl archive\n\n";
chdir("/home/stu/d/dbewley/www");
print `/usr/bin/tar -cf - perl | /usr/local/bin/gzip -c`;
--
# Dale Bewley
$contact = ( mailto:dlbe...@iupui.edu ||
http://www.engr.iupui.edu/~dbewley/perl/ );
I have solved the filename problem using the following Response
Header:
print "Content-type: application/zip\n";
print "Content-disposition: filename=\"$filename\"\n";
print "Content-length: [file size $filename]\n\n";
where $filename is preciously set to be the "hidden" file on the
server.
I still can't get the dang output right. IE, if I read a zip file I
want it to download as one. Somehow the format of the file gets hosed
such that the client can't determine what kind of file it is...
Terry Kasper
****************************************
* Digital Equipment Corporation
* Sales Force Automation
*
* Tel: 404.872.1353
* Fax: 404.874.3416
*
* Internet: kas...@mail.dec.com
* Compuserve: 102175,1553
****************************************
In comp.lang.perl.misc,
gyl...@skypoint.com (Joe Ellis) writes:
:If you're going to be sending image/binary data, make sure to BINMODE() the
:filehandles involved before you print any data.
There is no BINMODE() function.
tHERE IS A binmode() FUNCTION.
--tom
--
Tom Christiansen Perl Consultant, Gamer, Hiker tch...@mox.perl.com
"Sometimes I wish I could put an expiration date on my quotes." --Larry Wall
: I have solved the filename problem using the following Response
: Header:
: print "Content-type: application/zip\n";
: print "Content-disposition: filename=\"$filename\"\n";
: print "Content-length: [file size $filename]\n\n";
: where $filename is preciously set to be the "hidden" file on the
: server.
This only works for some browsers. Netscape for Windows won't see the filename, and neither does Mosaic. The only browser I've tested that actually notices
the content-disposition filename is Netscape 2.0 for X Windows.
Browsers that don't see this will often work if you provide the desired filename
in the PATHINFO area of the url you link with. IE, something like:
<a href="http://foo.bar.com/pushfile.pl/filename.zip?getdatagoeshereifany">filename</a>
If you're going to be sending image/binary data, make sure to BINMODE() the
filehandles involved before you print any data.
: I still can't get the dang output right. IE, if I read a zip file I
: want it to download as one. Somehow the format of the file gets hosed
: such that the client can't determine what kind of file it is...
: Terry Kasper
: ****************************************
: * Digital Equipment Corporation
: * Sales Force Automation
: *
: * Tel: 404.872.1353
: * Fax: 404.874.3416
: *
: * Internet: kas...@mail.dec.com
: * Compuserve: 102175,1553
: ****************************************
--
Joi Ellis
gyl...@skypoint.com
joi....@cdc.com
: [courtesy cc of this posting sent to cited author via email]
:
:In comp.lang.perl.misc,
: gyl...@skypoint.com (Joe Ellis) writes:
::If you're going to be sending image/binary data, make sure to BINMODE() the
::filehandles involved before you print any data.
:
:There is no BINMODE() function.
:tHERE IS A binmode() FUNCTION.
as long as we're on this subject - if I am setting up a download of a binary,
is there a header tag to set a file name?
Currently, if my script (download.pl) is set to download some file
(utility.exe), the user is given a file-save dialog box that has the
script name in it as the default value rather than the file name.
Any way to change that?
TIA.
Dave
--
David S. April Northwestern University
(708) 467-1903 Institute for the Learning Sciences
DAVID...@ameritech.com 1890 Maple Evanston, IL 60201
"Paradise is exactly like where you are right now, only much, much, better."
- Laurie Anderson