hosted by liquidweb


Go Back   Web Hosting Talk : Web Hosting Main Forums : Programming Discussion : Perl Help..
Reply

Programming Discussion Discussions related to web programming languages and other related issues. Topics may include configuration, optimization, practical usage and database connectivity.
Forum Jump

Perl Help..

Reply Post New Thread In Programming Discussion Subscription
 
Send news tip View All Posts Thread Tools Search this Thread Display Modes
  #1  
Old 09-19-2002, 10:09 PM
Mbarb Mbarb is offline
WHT Addict
 
Join Date: Oct 2000
Location: Midwest
Posts: 159

Perl Help..


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

PHP Code:
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

__________________
"Windows has detected the mouse has moved, Please restart your system
for changes to take effect."

Reply With Quote


Sponsored Links
  #2  
Old 09-20-2002, 12:04 AM
YUPAPA YUPAPA is offline
Quant Trader
 
Join Date: May 2001
Location: HK
Posts: 2,931
Smile

IS location OK?!?!?!

Code:
#!/usr/bin/perl
use strict;

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

__END__

Reply With Quote
  #3  
Old 09-20-2002, 12:47 AM
Mbarb Mbarb is offline
WHT Addict
 
Join Date: Oct 2000
Location: Midwest
Posts: 159
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..

__________________
"Windows has detected the mouse has moved, Please restart your system
for changes to take effect."

Reply With Quote
Sponsored Links
  #4  
Old 09-20-2002, 03:10 AM
chrisb chrisb is offline
Disabled
 
Join Date: May 2001
Posts: 1,513
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?

Reply With Quote
  #5  
Old 09-20-2002, 09:31 AM
Mbarb Mbarb is offline
WHT Addict
 
Join Date: Oct 2000
Location: Midwest
Posts: 159
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..

__________________
"Windows has detected the mouse has moved, Please restart your system
for changes to take effect."

Reply With Quote
  #6  
Old 09-20-2002, 09:53 AM
Rich2k Rich2k is offline
Web Hosting Master
 
Join Date: May 2002
Location: UK
Posts: 2,994
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

Code:
<!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
  >

Reply With Quote
  #7  
Old 09-20-2002, 02:13 PM
priyadi priyadi is offline
Registered User
 
Join Date: Apr 2001
Location: Depok, Indonesia
Posts: 986
Quote:
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.

Reply With Quote
  #8  
Old 09-20-2002, 05:42 PM
chrisb chrisb is offline
Disabled
 
Join Date: May 2001
Posts: 1,513
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?

Reply With Quote
  #9  
Old 09-20-2002, 06:27 PM
Mbarb Mbarb is offline
WHT Addict
 
Join Date: Oct 2000
Location: Midwest
Posts: 159
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.

Quote:
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?

__________________
"Windows has detected the mouse has moved, Please restart your system
for changes to take effect."

Reply With Quote
  #10  
Old 09-20-2002, 06:29 PM
Rich2k Rich2k is offline
Web Hosting Master
 
Join Date: May 2002
Location: UK
Posts: 2,994
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.

Reply With Quote
Reply

Related posts from TheWhir.com
Title Type Date Posted
cPanel & WHM Software 11.36 Reaches Stable Tier Status Web Hosting News 2013-04-09 11:44:33
cPanel Security Updates Address Perl Module Vulnerabilities Web Hosting News 2012-12-06 12:55:54
Softaculous Launches AMPPS Installer Version 1.5 Web Hosting News 2012-01-26 16:52:40
Web Host Liquid Web Donates $10,000 to The Perl Foundation Web Hosting News 2011-09-23 18:45:40
Web Host A2 Hosting Launches QuickInstaller Tool for VPS Plans Web Hosting News 2011-08-19 20:00:53


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes
Postbit Selector

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump
Login:
Log in with your username and password
Username:
Password:



Forgot Password?
Advertisement:
Web Hosting News:



 

X

Welcome to WebHostingTalk.com

Create your username to jump into the discussion!

WebHostingTalk.com is the largest, most influentual web hosting community on the Internet. Join us by filling in the form below.


(4 digit year)

Already a member?