Download file with PHP
ตัวอย่าง code สำหรับดาวน์โหลดไฟล์โดยไม่ให้ใครรู้ url ของไฟล์ที่กำลังดาวน์โหลด
<?php
define('DOCUMENT_FOLDER','docs/');
// add .pdf file extension
$filename=$_GET['file'].'.pdf';
$body='
Download file '.$filename.'
';
// get filename to download from DOCUMENTFOLDER or select from database
$file=DOCUMENTFOLDER.$filename;
$body.='
Start downloading file '.$filename.'
';
if (fileexists($file) && isfile($file)) {
header('Content-type: application/pdf');
header('Content-Disposition: attachment; filename="'.$filename.'"');
readfile($file);
} else {
$body.='
Download file '.$filename.' not found.
';
}
echo '
Download
'.$body.'
';
?>