Web Hosting Talk







View Full Version : Perl Help..


Mbarb
09-19-2002, 10:09 PM
Warning.. I'm really new at perl so excuse me if this is a easy question....

I'm trying to force a HTML file to download instead of displaying after clicking a link with in a perl file...

I have a link in the perl file that will say Download. When the link is clicked the save file dialog box should appear in the users browser and allow the user to save the HTML file.

I have this working from a standalone file but I would like to run it as a subroutine of an existing script.

Here is the problem as I see it. In order to force the download in the stand alone file I send these headers

print "Content-type: application/unknown\n\n";
print "Content-Disposition: inline; filename= $filename \n";

When I try to run it as a subroutine in the original script the headers are already sent (I need to send them to display the menu) so these headers just display as text on the screen.

any ideas


Sorry for my newbie-is-ness

YUPAPA
09-20-2002, 12:04 AM
IS location OK?!?!?!


#!/usr/bin/perl
use strict;

my $url = q(http://www.yourdomain.com/test.abc.file);
print "Location: $url\n\n";

__END__

Mbarb
09-20-2002, 12:47 AM
Nope, Sorry....

If I run it as you posted it it just places the URL in the address bar of the browser http://www.#######/64857/<http://www.##########/64857/messages/archive.html>
If I put the code in my existing script it just prints location on the screen..

Thanks for trying..

chrisb
09-20-2002, 03:10 AM
Doesn't sound like a perl question to me, and I don't know why you ned a subroutine for it. Try this where you call out the link.

<a href="download_filename.html" ENCTYPE="application/octet-stream">DOWNLOAD</a>

Did that help?

Mbarb
09-20-2002, 09:31 AM
HI,
I wish that had worked, the HTML displayed, it did not download the file.

I have a pretty good solution worked out in perl using one standalone script to serve the entire site. Thanks for the offers of help. I'll be glad to hear any other suggestions..

Rich2k
09-20-2002, 09:53 AM
You should try to put in the mime-type header the actual file type and not application/unknown.

Also the enctype addition to <a> is not a recognised standard so you should try to avoid it if at all possible

Here is the definition of the <a> tag from the XHTML 1.0 transitional DTD


<!ELEMENT a %a.content;>
<!ATTLIST a
%attrs;
%focus;
charset %Charset; #IMPLIED
type %ContentType; #IMPLIED
name NMTOKEN #IMPLIED
href %URI; #IMPLIED
hreflang %LanguageCode; #IMPLIED
rel %LinkTypes; #IMPLIED
rev %LinkTypes; #IMPLIED
shape %Shape; "rect"
coords %Coords; #IMPLIED
target %FrameTarget; #IMPLIED
>

priyadi
09-20-2002, 02:13 PM
Originally posted by Rich2k
You should try to put in the mime-type header the actual file type and not application/unknown.


The correct way to force download is to use application/octet-stream. However that won't work under IE, IE will still display the page on the browser according to the extension of the file. This is a violation of standard, but as IE holds more than 80% marketshare we are all forced to get around this problem. :(

chrisb
09-20-2002, 05:42 PM
IMHO, you have a content-type problem. Try putting this in an .htaccess file in the same directory.

Give the file a strange file extension, like .berl
Name it something.berl


AddType filename.berl application/octet-stream
AddHandler application/octet-stream .berl


Did it work?

Mbarb
09-20-2002, 06:27 PM
I would like to try this but for the site I'm working on this for it's just not possible. (1000's of user directories) I put together a stand alone script that works fine, I just pass the path information from the original script to the standalon script.

Originally posted by chrisb
IMHO, you have a content-type problem. Try putting this in an .htaccess file in the same directory.

Give the file a strange file extension, like .berl
Name it something.berl


AddType filename.berl application/octet-stream
AddHandler application/octet-stream .berl


Did it work?

Rich2k
09-20-2002, 06:29 PM
Well enc-type isn't a w3c standard for the <a> tag.

The most common and compatible method is content-disposition header... either inline or remote.