Solved

CGI "download" button!!

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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL several years ago, it seemed like now was a good time to update it for object-oriented PHP.  This article does that, replacing as much as possible the pr…
SASS allows you to treat your CSS code in a more OOP way. Let's have a look on how you can structure your code in order for it to be easily maintained and reused.
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…

617 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