Problem with force download


Read With Formatting | Free Open Source Tutorials Account

PHP Development
Thread: Problem with force download


convinceme
While trying to make user download a file using headers the connection seems to be lost after a while so could someone please tell me how to work it out
http://www.chaska.com.pk/c1.php << here is the page with the following code
file size = 4.19 MB
connection is lost at around 1.91 MB using 64kps cable internet connection
<?php
set_time_limit(0);
header('Content-Description: File Transfer');
header("Content-type: audio/mpeg"); //mp3 contenttype
header("Content-Disposition: attachment; filename=ek.mp3");
header('Content-length: '.filesize("ek.mp3"));
readfile("ek.mp3");
?>
your help in this regard would be highly appretiated

indy2kro
This usually happens because of the timeout. Every php is allowed to run only a small amount of time (by default 30 seconds). However, this is usually not enough when it comes to file download.

You can try to add this to your code: set_time_limit ( $seconds ) - where $seconds would be the amount you think it is safe for every user to download it.

However, that function is not available on all servers, especially if php is built in safe mode.