CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Intermediate:
Sending file from CGI Perl script ...

 



wilsonr
Deleted

Jun 24, 2000, 7:20 AM

Post #1 of 4 (927 views)
Sending file from CGI Perl script ... Can't Post

Hi all,

I want to be able to send a file from a CGI Perl script to a browser. I want the browser to act as normal i.e. popping up a window that gives the option of downloading or saving the file, however, I want to do this for html, gif, txt, etc i.e. I don't want them displayed in the browser window.

I don't want to have to present the browser with a link that they have to click on, I want this part to be automated.

Does anyone have any ideas how I could do this?

Best regards

Rod Wilson


Kanji
User

Jun 24, 2000, 9:04 AM

Post #2 of 4 (927 views)
Re: Sending file from CGI Perl script ... [In reply to] Can't Post

Have your CGI spit out "application/octet-stream" as the content type before displaying the document instead of the usual text/* or image/* content types.

The visitor should then be prompted to save the file, unless they're a complete moron who opted to automatically run unknown executables.

<BLOCKQUOTE><font size="1" face="Arial,Helvetica,sans serif">code:</font><HR>

if ( open FILE, "/path/to/some.gif" ) {
print "Content-Type: application/octet-stream\n\n",
<FILE>;
close FILE;
} else {
print "Content-Type: text/plain\n\n",
"Couldn't open some.gif because: $!\n";
}</pre><HR></BLOCKQUOTE>


wilsonr
Deleted

Jun 24, 2000, 2:08 PM

Post #3 of 4 (927 views)
Re: Sending file from CGI Perl script ... [In reply to] Can't Post

Hi Kanji,

Thanks for your reply.

I will give that a try.

Best regards

Rod


wilsonr
Deleted

Jun 26, 2000, 12:13 PM

Post #4 of 4 (927 views)
Re: Sending file from CGI Perl script ... [In reply to] Can't Post

Hi Kanji,

I tried that and it works ... but only with Netscape.

Thanks to Microsoft, they have 'added value' in Internet Explorer that seems to detect the file extension and ignore the octet-stream and treat it as html, gif, etc.

I did find a way around it though. I specified application/zip which must have fooled IE as it worked for html, gif, etc i.e. they downloaded rather than load in the browser.

Thanks again for your help, and I guess thanks to Microsoft for screwing things up!

Rod


 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives