Please help me with this problem. I have made a download script using php manual and post on php.net. And i must say it works ok except when someone cancel the download of the selected file and tries to download another one. Then the browser (Firefox, IE) open Save as dialog and offers file index.php
Does anyone know what i did wrong?
For help im submiting the script for dowload
<?
//Download a file using fpassthru()
$fileDir = "mapa/"; // supply a path name.
$query = "SELECT * FROM tabela WHERE id='$id'";
$r = mysql_query($query);
while($row=mysql_fetch_array($r)){
$file = $row[file];
$fileString=$fileDir.$file; // combine the path and file
echo $fileString;
// translate file name properly for Internet Explorer.
if (strstr($_SERVER['HTTP_USER_AGENT'], "MSIE")){
$file = preg_replace('/./', '%2e', $fileName, substr_count($file, '.') - 1);
}
// make sure the file exists before sending headers
if(!$fdl=@fopen($fileString,'r')){
die("Cannot Open File!");
} else {
header("Cache-Control: ");// leave blank to avoid IE errors
header("Pragma: ");// leave blank to avoid IE errors
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"".$file."\"");
header("Content-length:".(string)(filesize($fileString)));
sleep(0);
fpassthru($fdl);
exit();
}}
?>
Please if anyone knows what im talking about please help me or just kick me in the right direction.
Thanks for you help!