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 x+ mode in fopen() used for?

0 Answers  


how to open & closing opening period in fico

0 Answers   NS,


Can php run without server?

0 Answers  


How to remove values saved in the current session?

0 Answers  


What is the difference between InnoDB and MyIsam

1 Answers   Brain Technosys, IBM, TCS, TLI Software, Wipro,






Explain about the $_GET variable of PHP?

0 Answers  


How many ways there are to fetch the data from the Database?

2 Answers   Tops Technologies,


How to get ip address of a server in php?

0 Answers  


How to use the COM components in PHP?

2 Answers   HCL,


Is uploaded file php?

0 Answers  


This question is regarding version control. If two developers are committing the same php file at same time what will happen ? What error it will show (if any) ?

2 Answers   TCS,


What is the difference between nowdoc and heredoc?

0 Answers  


Categories