Menu
In my PHP code I am using the header() function to force the output file download. But the output renders to the browser itself and does’nt prompt the download window for the user to dowload the output file. I am also using include_once funtion to include some functions. If I remove the include_once function then the download window is prompted, but if the include_oce function is there then the output is rendered on to the browser itself. Could anyone please let me know what is mistake……
Thanks! in advance…..
[code=php]
<?php
$filename = $_GET['file'];
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
$file_extension = strtolower(substr(strrchr($filename,"."),1));
if( $filename == "" )
{
echo "<html><title>Download Script</title><body>ERROR: download file NOT SPECIFIED using download.php file</body></html>";
exit;
} elseif ( ! file_exists( $filename ) )
{
echo "<html><title>Download Script</title><body>ERROR: File not found using download.php file</body></html>";
exit;
};
switch( $file_extension )
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename="".basename($filename)."";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
?>
[/code]
try this.. works great for me!
somedomain.com/download.php?file=filename.type
"download.php"
[code=php]
<?php
$filename = $_GET['file'];
if(ini_get('zlib.output_compression'))
ini_set('zlib.output_compression', 'Off');
$file_extension = strtolower(substr(strrchr($filename,"."),1));
if( $filename == "" )
{
echo "<html><title>Download Script</title><body>ERROR: download file NOT SPECIFIED using download.php file</body></html>";
exit;
} elseif ( ! file_exists( $filename ) )
{
echo "<html><title>Download Script</title><body>ERROR: File not found using download.php file</body></html>";
exit;
};
switch( $file_extension )
{
case "pdf": $ctype="application/pdf"; break;
case "exe": $ctype="application/octet-stream"; break;
case "zip": $ctype="application/zip"; break;
case "doc": $ctype="application/msword"; break;
case "xls": $ctype="application/vnd.ms-excel"; break;
case "ppt": $ctype="application/vnd.ms-powerpoint"; break;
case "gif": $ctype="image/gif"; break;
case "png": $ctype="image/png"; break;
case "jpeg":
case "jpg": $ctype="image/jpg"; break;
default: $ctype="application/force-download";
}
header("Pragma: public"); // required
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Cache-Control: private",false); // required for certain browsers
header("Content-Type: $ctype");
// change, added quotes to allow spaces in filenames, by Rajkumar Singh
header("Content-Disposition: attachment; filename="".basename($filename)."";" );
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($filename));
readfile("$filename");
exit();
?>
[/code]
let me know if works 4 u ?[/QUOTE]
[code=php]
<html>
<head>
<script>
function redirect()
{
window.location.href = "download.php?file=abc.exe";
}
</script>
</head>
<BODY onload="javascript:setTimeout('redirect()', 0000)">
</</BODY> >
</html>
[/code]
[code=php]
<html>
<head>
</head>
<BODY>
<script type="text/javascript">
function delay()
{
window.location="download.php?file=abc.exe";
}
setTimeout(delay,0000)
</script>
</BODY>
</html>
[/code]
by the way, if your download.php file, and your abc.exe are in the same dir,
there's no need for the "myserver.com" part (as in "?file=myserver.com/abc.exe")
if the script in on your root dir, and if your .exe is on a sub dir, ("programs" for
example) then point the script like this:
myserver.com/download.php?file=programs/abc.exe
i wish this helps! ?[/QUOTE]
0.1.9 — BETA 5.27