How to download the files using PHP

Answer Posted / vishwapati_mishra

<?
$dir="/path/to/file/";
if (isset($_REQUEST["file"])) {
$file=$dir.$_REQUEST["file"];
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file));
header("Content-disposition: attachment;
filename=\"".basename($file)."\"");
readfile("$file");
} else {
echo "No file selected";
}
?>

Is This Answer Correct ?    7 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is get method in java?

535


List some features of php that are deprecated in php7?

473


Is string php function?

574


What language is php written in?

593


Explain some most commonly use string functions in php?

507






What is the use of $_server and $_env?

573


What is design pattern? Explain all including singleton pattern?

543


How to get ip address of clients machine?

564


How to get the value of current session id?

538


Do I need to install php after xampp?

539


How to return a value back to the function caller?

560


What does a dependant variable mean?

565


What is the difference between runtime exception and compile time exception?

547


What is the use of limit in mysql?

517


Explain what is memcache?

510