PHP download
Moderator: General Moderators
PHP download
How to code Download files like PDF,WORD etc..?
Re: PHP download
Can you elaborate a little on what you mean?
Re: PHP download
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.
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
What if you use
Code: Select all
readfile($path . "/" . $filename);