Support Forums

Full Version: [Function] Force download of a file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Coded by me, forces the default save dialog prompt to appear. Good if you want to hide a files original source.

PHP Code:
<?php
ob_start
();
// Example Usage: downloadfile("meandyourmom.png");
function downloadfile($file2d){
@
ob_clean(); 
@
$fh=fopen($file2d,'r');
@
$buffer=fread($fh,filesize($file2d));
header("Content-type: application/octet-stream");
header("Content-length: ".strlen($buffer));
header("Content-disposition: attachment; filename=".basename($file2d).';');
@
ob_get_clean();
echo 
$buffer;
@
fclose($fh);
@
ob_clean(); 
}
?>

You could also do something like unlink the file afterwards so they can't download it again.
You can also use this to save a file to your server