ตัวอย่าง code php ไว้ download ไฟล์จาก server
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 | PHP/download.php <?php $fileDir = '../assets/'; $token = 'HH89VOiirgXlCdEqDrFs'; if ($_REQUEST['token'] != $token) { exit('bad token'); } $file = $fileDir . $_REQUEST['file']; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: ' . mime_content_type($file)); header('Content-Disposition: attachment; filename="' . basename($file) . '"'); header('Expires: 0'); header('Cache-Control: must-revalidate'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); //readfile($file); echo file_get_contents($file); } else { exit('file not found'); } |
เพราะว่า ออกแบบให้สามารถโหลดไฟล์อะไรก็ได้จาก server เลยมีการใช้ token ช่วยในการตรวจสอบความปลอดภัยเล็กน้อย ของจริงต้องแก้ให้ตรวจ token ซับซ้อนกว่านี้เพื่อความปลอดภัย