Solved

CGI "download" button!!

Posted on 2002-06-18
7
210 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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Need help editing script 3 74
Automating a script for user accounts LINUX 14 73
Creating 2 files from output with Powershell 5 44
Randomize in Owl Carousel v1.3.2 6 44
What is Node.js? Node.js is a server side scripting language much like PHP or ASP but is used to implement the complete package of HTTP webserver and application framework. The difference is that Node.js’s execution engine is asynchronous and event…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

773 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