Forum Moderators: coopster
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";
}
?>
No, I haven't sorted this out yet. I took the download out of a popup window and tried in a target "_blank" which made no difference and then made it a direct link. Again, this didn't change anything, the browsing after continued to be not just slow, but unable to display the next page on the site until the download was stopped. I tried in four different web browsers to check it wasn't Firefox specific.
One thing I haven't posted in the code is that there is a PHP Session Control to prevent non-members accessing the downloads, would this be causing the problem?
One thing I haven't posted in the code is that there is a PHP Session Control to prevent non-members accessing the downloads, would this be causing the problem?
That is exactly your problem. The session is locking the connection, look at session_write_close() before you send the download stream.
That should fix your issue.
//add here
session_write_close();
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);
}
}
Cheers.