PHP download method hanging up page… best practices for pushing a download?

jeltknole

New Member
quick question: I've got a form that forces a user to enter an email, after which a download/attachment is pushed and a file is downloaded... the file downloads fine... however...My problem is that when the download starts, the page locks up, and the user can't navigate anywhere or do anything on the page until the file is downloaded (ie: clicking the "go home" link below). Any better solutions than what I come up with here? I know i'm probably missing something really simple ... this is my first crack at setting up a private download page.\[code\]<script type="text/javascript">function redirect_function(loc){ window.location = loc;}</script><?php// after form is submitted$condition_met=check($_POST['email']);if($condition_met) { ?> <p>Your file will begin downloading in 5 seconds.</p> <a>go home</a> <script type="text/javascript"> setTimeout('redirect_function("download.php")', 5000); </script><?php } ?>\[/code\]The called (download.php) page looks like this, this is where it hangs up the page...\[code\]<?phpob_start();if($some_condition) { // check for authorization, etc $file='location/file.ext'; header('Content-type: application/force-download'); header('Content-disposition: attachment; filename="'. basename($file) .'"'); header('Content-length: '. filesize($file) ); readfile( $file );} else { echo "error message";}ob_end_flush();?>\[/code\]
 
Back
Top