Page 1 of 1
PHP download
Posted: Wed Sep 21, 2011 11:34 pm
by mnewman
How to code Download files like PDF,WORD etc..?
Re: PHP download
Posted: Thu Sep 22, 2011 6:59 am
by Celauran
Can you elaborate a little on what you mean?
Re: PHP download
Posted: Thu Sep 22, 2011 6:22 pm
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.
Re: PHP download
Posted: Thu Sep 22, 2011 7:10 pm
by Celauran
What if you use
Code: Select all
readfile($path . "/" . $filename);