Solved

How to start a file download using CGI?

Posted on 1997-11-08
4
323 Views
Last Modified: 2013-12-25
I am trying to implement a single HTML Web page at my Web site that performs two actions:

1) Prompt the visitor for their email address and then...

2) Start a download of a specific .ZIP file


I have a form on a Web page (example):

<form
action="https://www.mysite.com/myaccount/cgibin/download.cgi"
method="POST">
<input type="hidden" name="THISPROGRAM" value="DOWNLOAD">

<input type="text" size="30" name="address">
</form>

...and I know enough about CGI/Perl to be dangerous.  The current CGI script
I use can retrieve the email "address" input from this form and use it. This is no problem.  I am fine here.  However, my problem is I don't know how a CGI script can initiate a file transfer, in this case MYPROG.ZIP
located at:   www.mysite.com/pub/myprog.zip to the visitor's browser.

I wish that a form action could run TWO commands at the same time, but I fear that this is not possible, therefore I must initiate the file download/transfer from the cgi script (which I don't know how to do).

Any suggestions and examples would be greatly appreciated.
0
Comment
Question by:Kapusta
  • 3
4 Comments
 

Author Comment

by:Kapusta
ID: 1831118
Edited text of question
0
 

Author Comment

by:Kapusta
ID: 1831119
Adjusted points to 150
0
 

Author Comment

by:Kapusta
ID: 1831120
Adjusted points to 250
0
 
LVL 6

Accepted Solution

by:
alamo earned 250 total points
ID: 1831121
This is done via a redirect, i.e. your perl script would write as the only header:

print "Location: http://www.mysite.com/pub/myprog.zip\n\n";

This will send a signal to the browser which will turn around and get the file. The only drawback is the user will be left looking at the page with the original form, you can't send the suer another message. On the plus side though,  the URL of the file won't show on the Location: line.

Does this meet your needs? If not, leave a comment and I'll change it... good luck!

0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Introduction This tutorial will give you a fast look what you can do with WhizBase. I expect you already know how to work with HTML at least, and that you understand the basics of the internet and how the internet works. WhizBase is a server-s…
This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

679 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