File Download code using php is very simple and effective.Using this code you can download any file,doc,pdf,rar,zip,video,image etc.just you have to add file path to this function.This is done by a some line of php code. 
Download any type of file using php script.This code is help you to download any kind of file dynamically.
Example code : 
//your file name add
$f="test.php";
function force_download($file)
{
//provide your directory path
$dir="";
if ((isset($file))&&(file_exists($dir.$file))) {
header("Content-type: application/force-download");
header(‘Content-Disposition: inline; filename="’ . $dir.$file . ‘"’);
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($dir.$file));
header(‘Content-Type: application/octet-stream’);
header(‘Content-Disposition: attachment; filename="’ . $file . ‘"’);
readfile("$dir$file");
} else {
echo "No file selected";
} 
}//end function
echo force_download($f);

No comments:
Post a Comment
Thanks....