Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Function] Force download of a file
#1
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.
Reply
#2
You can also use this to save a file to your server
I am your Father
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Noob's doubt on echo function in php mandi 5 1,735 12-09-2010, 06:00 AM
Last Post: Orgy
  [Function] XOR Encryption/Decryption with a Key OX!DE 0 2,244 02-21-2010, 07:14 PM
Last Post: OX!DE
  [Function] Test HTTP/Socks 4/Socks 5 Proxy OX!DE 0 2,625 02-21-2010, 07:10 PM
Last Post: OX!DE
  Email PHP function and connecting it to a form Tasemu 3 2,384 10-09-2009, 05:22 AM
Last Post: Tasemu

Forum Jump:


Users browsing this thread: 1 Guest(s)