Solved

CGI "download" button!!

Posted on 2002-06-18
7
218 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Fulfillment API php code sample 1 95
Help with Progress 4gl Rounding Function 6 60
Powershell- Registry HIVE 6 63
Running Scripts (per users) after OS deployment 2 47
Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System (http://www.experts-exchange.com/A_2902.html) introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
This article covers the basics of the Sass, which is a CSS extension language. You will learn about variables, mixins, and nesting.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

751 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