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

Is php a framework?

0 Answers  


Explain Booleans in PHP?

0 Answers  


How can we know the total number of elements of Array?

0 Answers  


How to enable parsing?

0 Answers  


How to strip whitespace (or other characters) from the beginning and end of a string?

0 Answers  






What is isset in php?

0 Answers  


What is putenv?

0 Answers  


What is string function sql?

0 Answers  


what are the current or latest versions of LAMP ? Linux, Apache, MySql, PHP

4 Answers  


Explain different types of errors in PHP (i.e. arguments in errorreporting function)?

8 Answers   Base2 Infotech, DCI, Microsoft, Tata Elxsi,


What are form input html tags?

0 Answers  


Explain how to execute a php script using command line.

0 Answers  


Categories