Solved

How to start a file download using CGI?

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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

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…
I hope you'll find this tutorial useful and interesting. So let's try to extend Tcl with a new package.  For anyone more deeply interested please check out the book "Practical Programming in Tcl and Tk". It's really one of the best written books abo…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

758 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now