hi everyone,
i am using the following code to make a secure download in my site:
everything seems to work, except when i download the file,
i have a "unknown time remaining" text on the download,
for some reason the browser does not know the size of the file , even though i have set the headers correctly.
any idea what i'm doing wrong here?
i am using the following code to make a secure download in my site:
Code:
<?
include "common.php";
commonConnectToDB();
$sql = "select * from contacts where now()-insertTime < 180";
$res = commonDoQuery($sql);
if (mysql_num_rows($res) == 0)
return;
$asfname = "MyFileName.exe";
$filename = commonGetLayoutSwitchHtml("trialDownloadFileName", "ENG");
$realFileName = "loadedFiles/$filename";
$fsize = filesize($realFileName);
/* waiting for PHP 5.3
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$mtype = finfo_file($finfo, $filename);
finfo_close($finfo);
*/
$mtype = "application/exe";
// set headers
header("Pragma: no-cache");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Description: File Transfer");
header("Content-Length: $fsize");
header("Content-Type: $mtype");
header("Content-Disposition: attachment; filename=\"$asfname\"");
header("Content-Transfer-Encoding: binary");
//flush();
$file = @fopen($realFileName,"rb");
if ($file) {
while(!feof($file)) {
print(fread($file, 1024*8));
flush();
if (connection_status()!=0) {
@fclose($file);
die();
}
}
@fclose($file);
}
?>
i have a "unknown time remaining" text on the download,
for some reason the browser does not know the size of the file , even though i have set the headers correctly.
any idea what i'm doing wrong here?
Comment