Solved

How to start a file download using CGI?

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

How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

Question has a verified solution.

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

Introduction:   Welcome to my first article ever. To begin with, the reason I write this article.  I participated in a question on Experts Exchange about the start command in Windows and there were some discussion about the usage. The discussio…
It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Learn the basics of lists in Python. Lists, as their name suggests, are a means for ordering and storing values. : Lists are declared using brackets; for example: t = [1, 2, 3]: Lists may contain a mix of data types; for example: t = ['string', 1, T…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. 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.: (CODE)

860 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