Solved

How to start a file download using CGI?

Posted on 1997-11-08
4
321 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

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

If you get a (Blue Screen of Death), your system writes a small file called a minidump. Your first step is to make certain your computer is setup to record memory dumps. Right click My Computer, choose properties. Click on the advanced tab, an…
In this tutorial I will show you how to make a simple HTML bar chart with the usage of WhizBase, If you want more information about WhizBase please read my previous articles at http://www.experts-exchange.com/ARTH_5123186.html (http://www.experts-ex…
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…
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

778 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