I’ve written a download script to act as a proxy for files on my website so people can’t get a direct link. The script works perfect, except that when you try to continue browsing after the file download has started, you can’t!
A direct link to the file causes no such problem, you can continue to browse through the site, but when downloading through the download.php file, you can’t - it just times out.
Here’s my script:
<?php
# Declare function
function send_download($filename,$phone_model){
$file_path = "software/$phone_model/$filename";
$filetype = strrchr($filename,'.');
$ext = strtolower($filetype);
$ext = str_replace(".", "", $ext);
switch($ext) {
case "zip":
$ext = 'application/zip';
break;
case "exe":
$ext = 'application/octet-stream';
break;
case "dmg":
$ext = 'application/x-apple-diskimage';
break;
}
$file_size = filesize($file_path);
// I even tried to limit the d/l rate which didn't help
$download_rate = 1.5;
header("Content-Description: File Transfer");
header("Content-Type: $ext");
header("Content-disposition: attachment; filename=$filename");
header("Content-Transfer-Encoding: binary");
header("Content-Length: $file_size");
//readfile($file_path);
$file = @fopen($file_path,"rb");
if ($file) {
while(!feof($file)) {
set_time_limit(0);
print fread($file, round($download_rate * 1024));
flush();
sleep(1);
if (connection_status()!=0) {
@fclose($file);
die();
}
}
@fclose($file);
}
}
if (isset($_GET['file'])){
$file = $_GET['file'];
$member_query = mysql_query("SELECT * FROM members WHERE email_address = '$memberID'") or die (mysql_error());
while ($r = mysql_fetch_array($member_query)) {
$phone_model = $r["phone_model"];
}
if (file_exists("software/$phone_model/$file")) {
send_download($file, $phone_model);
} else {
echo "You Are Not Allowed to Download This Content";
}
} else {
echo "Error";
}
?>
This page opens in a blank window and sends the file. Can anyone see why it would slow down/stop the browsing in the parent window? Please help! This is not a browser specific bug either - tested in IE, Firefox, Chrome and Mac based Safari - all with the same results.