Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

CGI "download" button!!

Posted on 2002-06-18
7
Medium Priority
?
223 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 200 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

PowerShell Core for Advanced Linux Administrators

Understand advanced principals around Powershell Core with a focus on the Linux Administrator.  This course covers how to administer numerous environments across multiple platforms including Linux, Azure, AWS, and Google Cloud from a single shell instance.

Question has a verified solution.

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

Styling your websites can become very complex. Here I'll show how SASS can help you better organize, maintain and reuse your CSS code.
The Windows functions GetTickCount and timeGetTime retrieve the number of milliseconds since the system was started. However, the value is stored in a DWORD, which means that it wraps around to zero every 49.7 days. This article shows how to solve t…
HTML5 has deprecated a few of the older ways of showing media as well as offering up a new way to create games and animations. Audio, video, and canvas are just a few of the adjustments made between XHTML and HTML5. As we learned in our last micr…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

715 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