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

What is MVC structure in Magento?

4 Answers  


can any one tell how to install LAMP server in terminal in ubuntu.....and also tell please how to run php files in ubunut and how to save and compile in ubuntu..i already installed ubuntu ..but i dont installed lamp server so i want to install lamp server in terminal is it possible please reply

2 Answers  


What does nan stand for computer science?

0 Answers  


Tell me what does the array operator '===' means?

0 Answers  


What are the limitations or drawbacks of PHP ?

4 Answers   iDream,






Difference between get and post method.

0 Answers  


How can we get the properties (size, type, width, height) of an image using PHP image functions?

4 Answers   ConSim,


Explain array_uintersect()?

0 Answers  


what is the default method of form in php?

6 Answers  


What is difference between echo and print in php?

0 Answers  


1.What are the difference between echo , print , print_r ? else this 3 can we show output to a client in some other way?

16 Answers   Leeway Hertz,


Do you know how to delete a file from the system?

0 Answers  


Categories