Solved

CGI "download" button!!

Posted on 2002-06-18
7
204 Views
Last Modified: 2013-12-25
I have a CGI form (written in Perl) that has a "button".
When this button is pressed, it should let user (client),
download a file (without opening the file) from the server
to the client's computer.
I know the location in server from where the user will
download the file. User (client) should get a dialog box
(after pressing the button) and will be prompted to
store the file in their location of choice in their computer.

How do I do this?please help.
-tooki
0
Comment
Question by:tooki
  • 3
7 Comments
 
LVL 12

Accepted Solution

by:
lexxwern earned 50 total points
ID: 7093079
when in perl you include the html download..

it would be like this
print qq(
<input type="button"/>
);


replace your html with this

<input type="button" onclick="window.location='download.zip'"/>


here i have used javascript to start the download.
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7093081
lets the browser handle what the user sees for download.
0
 

Author Comment

by:tooki
ID: 7094526
Thanks lexxwern,
<input type="button" click="window.location='download.zip'"/>

This works but the browser tries to open the file, and the file I need user(client) to download is a text file (.txt) and with above code, the text file opens up on the browser!
Any other way that it will directly go to "Save As" option to the user?
thanks.-tooki
0
 
LVL 12

Expert Comment

by:lexxwern
ID: 7094549
the safest method would be to change the extension of the file to something else and ask the downloader to open in notepad.

or you can ask you host to change the mime types. i bet he will refuse.
0
 
LVL 11

Expert Comment

by:mouatts
ID: 7098063
No you don't change the file type or the mime-type on the server, you change the mime-type on the response.

Basically your cgi must output the following headers

content-type: application/octet-stream
content-disposition: filename=myfile.txt

HTH
Steve
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
JavaScript has plenty of pieces of code people often just copy/paste from somewhere but never quite fully understand. Self-Executing functions are just one good example that I'll try to demystify here.
The viewer will learn how to dynamically set the form action using jQuery.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now