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

I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what is the problem?

492


Which will start a session?

568


How do you pass a variable by value in php?

532


What is input sanitization in php?

532


How check submit button is clicked in php?

509






What are the differences between GET and POST methods in form submitting?

554


How to call javascript function in php on button click?

503


How to do single and multi line comment in php?

542


Tell me what are the correct and the most two common way to start and finish a php block of code?

516


What is abstract class php?

508


What is null value in php?

558


can we swap two different string using php for example:-- before swapping:-- 1 string :-hello friend, 2 string :-my dear, after swapping that strings will be: 1.hello dear, 2.my friend.

3056


What is the latest version of php?

524


Explain PHP?

603


Is server side a session?

489