PHP download

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
mnewman
Forum Newbie
Posts: 10
Joined: Tue Sep 20, 2011 7:53 pm

PHP download

Post by mnewman »

How to code Download files like PDF,WORD etc..?
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP download

Post by Celauran »

Can you elaborate a little on what you mean?
User avatar
mnewman
Forum Newbie
Posts: 10
Joined: Tue Sep 20, 2011 7:53 pm

Re: PHP download

Post by mnewman »

include 'db1.php';

if(isset($_GET['file_id'])){
$file_id=(int)$_GET['file_id'];

$download=mysql_query("SELECT * FROM download WHERE file_id='$file_id'");
$downloadrow=mysql_num_rows($download);
if($download!=0){
$row=mysql_fetch_assoc($download);
$filename=$row['file_name'];
$path="../download";
header("Content-Type: application/zip");
header("Content-Description: File Transfer");
header("Content-Desposition: attachment; filename = $filename");
header("Content-Length: filesize($path)");
header("Content-Transfer-Encoding: binary");
header("Cache-Control:public");
readfile($path , $filename);
}

}

i dont know what's the problem..every time i test it,instead of downloading the file selected..it downloads the page.
User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP download

Post by Celauran »

What if you use

Code: Select all

readfile($path . "/" . $filename);
Post Reply