How to download the files using PHP



How to download the files using PHP..

Answer / 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

More PHP Interview Questions

How do you execute a php script from the command line?

0 Answers  


How to uploaded files to a table?

0 Answers  


Tell me what the difference between the 'bitwise and' operator and the 'logical and' operator?

0 Answers  


what is php stands for?

23 Answers   Infosys, Satyam, Torque Infotech,


How to split a string into array using php?

0 Answers  


What is php key?

0 Answers  


What is php and how do you use it?

0 Answers  


how to include external php file in to html page?

8 Answers   Eccentric Infotech,


how to run PHP in command line?

8 Answers   InfoShore, Ramp Green, Xtreeme,


Explain the different types of errors in php.

0 Answers  


What is csrf cookie?

0 Answers  


Does php have multiple inheritance?

0 Answers  


Categories