php 檔案下載
阿新 • • 發佈:2018-12-16
<?php $document=$db->getRow("SELECT file_name,file_url FROM documents WHERE id='".$_REQUEST['id']."'"); $fileUrl = $document['file_url']; $fileName = $document['file_name']; /** * 檔案下載 * @parameter $urlUrl 檔案的url地址 例如'./index.html' * @parameter $fileName 下載下來新的檔名字 例如'測試1' */ if (file_exists($urlUrl)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.$fileName); header('Content-Transfer-Encoding: binary'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header('Pragma: public'); header('Content-Length: ' . filesize($file)); ob_clean(); flush(); readfile($file); exit; } >