Question:
How do download in php ?
Answer:
It is very simple,
just give the link to the file that we want to download, if it is an html file, will display and other files get downloaded. [ Server Side Scripting files not get downloaded ]. Source: CoolInterview.com
Answered by: Fahad K P | Date: 7/8/2009
| Contact Fahad K P
We can Implement the download a file program by twodays 1)read a file with fopen and give the path of that file. 2)by using header function like ex:To download .doc file header('content-tye:text/doc') header('Content-Disposition: attachment; filename="downloaded.doc"'); header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1 header("Expires: Sat, 26 Jul 1997 05:00:00 GMT"); Source: CoolInterview.com
Answered by: shyambabu | Date: 8/12/2009
| Contact shyambabu
The answer is through header.
header('Content-type: application/image');
header('Content-Disposition: attachment; filename="myimg.jpg"');
readfile('myimg.jpg'); Source: CoolInterview.com
Answered by: Munjal | Date: 9/22/2009
| Contact Munjal
<?php ob_start(); require('connect.php');//connection to the database $id=$_GET['userId']; $result=mysql_query("select file_name, file_type from table_name where user_id='$id'"); $row=mysql_fetch_array($result); $fn=$row['file_name']; $ft=$row['file_type']; $path="uploads/photos/$id"; header("Content-Disposition: attachment; filename=$fn");
header("Content- Type:application/$ft");
header("Content-Length: ".filesize("$path/$fn")); header("Pragma: no-cache"); header("Expires: 0"); $fp=fopen("$path/$fn","r"); print fread($fp,filesize("$path/$fn")); fclose($fp); exit();
ob_end_flush();
?> Source: CoolInterview.com
Answered by: Rajeev Nayan | Date: 10/8/2009
| Contact Rajeev Nayan
If you have the better answer, then send it to us. We will display your answer after the approval.
Rules to Post Answers in CoolInterview.com:-
- There should not be any Spelling Mistakes.
- There should not be any Gramatical Errors.
- Answers must not contain any bad words.
- Answers should not be the repeat of same answer, already approved.
- Answer should be complete in itself.
|