Reply to Re: Downloads, headers and scripts not finishing...

Your name:

Reply:


Posted by Jerry Stuckle on 10/20/07 20:11

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($zipdir . '/' . $zipfilename));
> header('Content-Disposition: attachment;
> filename="'.$zipfilename.'"');
>
> // 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.
jstucklex@attglobal.net
==================

[Back to original message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация