473,815 Members | 2,307 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Downloads, headers and scripts not finishing...


I may be having an attack of the stupids and my Google-foo is
failing me today, but I can't seem to get past this problem.
I have a script that indexes a directory and provides the user
with a simple interface to select files to download.

Once they've made their selection and submitted the form, the form
action reloads the page.

On reload, the script checks for the presence of POST variables
and, if not found, redisplays the previous form or, if found collects
files for download.

If this is the first request, the target files are collected into
a ZIP file and saved to the server for reuse.

Then the script serves the saved file to the user for download
with the following code:

---

header('Pragma: public');
header('Content-type: application/zip');
header('Content-length: ' . filesize($zipdi r . '/' . $zipfilename));
header('Content-Disposition: attachment;
filename="'.$zi pfilename.'"');

// readfile( $zipdir . '/' . $zipfilename );
if ( ( $fp = fopen( $zipdir . '/' . $zipfilename, 'rb' ) ) === false )
exit;
@fpassthru( $fp );
@fclose( $fp );

---

This all works fine. The commented out readfile() _also_ worked
fine, but I've been trying to see how to get past my problem, which
is:

Once the file is sent to the output stream, the script seems to
halt.

I want to get the script to continue rendering a 'Thank you for
downloading...'-type page, but nothing seems to happen after the
readfile() or fpassthru().

In practical terms, this is nothing more than an annoyance. The
end user gets the requested ZIP file, but nothing else can be done in
the script. (I have a 'busy' graphic that I unhide on form submission
that I want to hide again upon completion.)
What am I forgetting? Is there something in the header man pages
that I've missed?

Other examples I've searched for online seem to imply that script
execution should continue.
Any thoughts would be appreciated.

-Joe
Oct 20 '07 #1
2 1463
Dahak wrote:
I may be having an attack of the stupids and my Google-foo is
failing me today, but I can't seem to get past this problem.
I have a script that indexes a directory and provides the user
with a simple interface to select files to download.

Once they've made their selection and submitted the form, the form
action reloads the page.

On reload, the script checks for the presence of POST variables
and, if not found, redisplays the previous form or, if found collects
files for download.

If this is the first request, the target files are collected into
a ZIP file and saved to the server for reuse.

Then the script serves the saved file to the user for download
with the following code:

---

header('Pragma: public');
header('Content-type: application/zip');
header('Content-length: ' . filesize($zipdi r . '/' . $zipfilename));
header('Content-Disposition: attachment;
filename="'.$zi pfilename.'"');

// readfile( $zipdir . '/' . $zipfilename );
if ( ( $fp = fopen( $zipdir . '/' . $zipfilename, 'rb' ) ) === false )
exit;
@fpassthru( $fp );
@fclose( $fp );

---

This all works fine. The commented out readfile() _also_ worked
fine, but I've been trying to see how to get past my problem, which
is:

Once the file is sent to the output stream, the script seems to
halt.

I want to get the script to continue rendering a 'Thank you for
downloading...'-type page, but nothing seems to happen after the
readfile() or fpassthru().

In practical terms, this is nothing more than an annoyance. The
end user gets the requested ZIP file, but nothing else can be done in
the script. (I have a 'busy' graphic that I unhide on form submission
that I want to hide again upon completion.)
What am I forgetting? Is there something in the header man pages
that I've missed?

Other examples I've searched for online seem to imply that script
execution should continue.
Any thoughts would be appreciated.

-Joe
Joe,

Yes, that's normal. When the browser gets the zip file content header,
it won't be expecting html (or vice versa). File downloads are
typically a "dead end" - nothing more in that window following the download.

The easy way around this is to display your page again with a clickable
link to the zip file. That way you can display HTML and yet allow the
user to download the file. And if you want to automate it, a little
javascript can be used to start the actual download.

--
=============== ===
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attgl obal.net
=============== ===

Oct 20 '07 #2
On Sat, 20 Oct 2007 16:11:43 -0400, an orbiting mind-control laser
made Jerry Stuckle <js*******@attg lobal.netwrite:
>Joe,

Yes, that's normal. When the browser gets the zip file content header,
it won't be expecting html (or vice versa). File downloads are
typically a "dead end" - nothing more in that window following the download.

The easy way around this is to display your page again with a clickable
link to the zip file. That way you can display HTML and yet allow the
user to download the file. And if you want to automate it, a little
javascript can be used to start the actual download.

Thanks for the clarification.

I appreciate the help.

-Joe
Oct 20 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7609
by: Seagull Manager | last post by:
Running Apache 1.3, PHP 4.3, and WinXP, configured acc. to instructions on apache manual and php manual (as far as I can see), but getting "internal server error" in browser... log says "Premature end of script headers" for my simple test scripts PHP runs fine from the command line, incidentally I tried changing the doc_root in php.ini from blank to the path of htdocs -- no difference.
4
8576
by: | last post by:
I want send my zip files in my page from inside php. With this I know how many people have download my file and other information. My problem is this, I have this code but it dosn't resume broken downloads. What I can do for this? ------------------- <?php header('Content-type: application/zip'); $fp = fopen('file.zip', 'rb');
10
3045
by: Lisa Pearlson | last post by:
Hi, I have a php script with no more than this: <?php echo "Hello World!"; ?> When a webbrowser client requests data, it receives Apache server headers, followed by my data: HTTP/1.1 200 OK
0
1151
by: Benjamin Han | last post by:
A while ago I asked if anyone knows a module for parsing Received: headers in emails. Apparently my guess was wrong (that someone already wrote it in Python). I got an email pointing me to Spambayes project, however the tokenizer doesn't seem like doing a lot on the Received headers (especially when comparing to SpamAssassin's code). So I wrote a small set of scripts for doing this: ...
3
2340
by: sachin | last post by:
i'm hosting mp3s on a private server I'd like to track downloads...specifically: -IP address -Unique downloads -Downloads per day or week thanks -sachin
3
1897
by: jaschreiber | last post by:
hi. i have a couple scripts on my site that send emails, and they've all been working for months with no problems. all of a sudden the from headers aren't working, so the messages all come from the server (texasnee@web012.ahp01.lax.affinity.com) instead of the address specified. i haven't changed anything in the scripts and i didn't (knowingly) make any changes to the server.... does anyone have any idea what might have happened? ...
22
2231
by: Platero | last post by:
Hi, I've a stupid question but... The code is the following: if(($role!='tutor')&&(array_key_exists('tutor_id',$_GET))) { $possible_ids = array(2,6,7,8,9,10); $t_id = $_GET;
5
3072
by: Milos Prudek | last post by:
I perform a XML-RPC call by calling xmlrpclibBasicAuth which in turn calls xmlrpclib. This call of course sends a HTTP request with correct HTTP headers. The response is correctly parsed by xmlrpclib, and I get my desired values. However, I also need to get the raw HTTP headers from the HTTP response. There is a cookie in the HTTP response and I need to read that cookie. How could I do that?
14
1586
by: Dave | last post by:
Hello, Not sure if this is php related or not, but i'd like to have certain users who have the ability to upload files to my site, and others to download files. I thought about .htaccess and basic authentication, but then i thought that's not very secure i was wondering if there was a php solution, something that splits user uploads and downloads in to two separate sections? I checked out some scripts on phpbuilder.com but they don't seem...
0
9735
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
1
10427
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10143
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9225
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6897
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5710
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4358
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3886
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3030
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.