PHP 下載檔案隱藏路徑,做過檔案下載安全性的進來看看哦!
最近在弄檔案資源管理,在下載時隱藏檔案路徑採用的方案僅僅是,對存放檔案的目錄用apache配置使之無法直接存取目錄列表,rewrite技術可隱藏伺服器的目錄!
比如下載路徑本來為:http://miresearch.cn/uploadfile/resource/2012-05/8F4F5A42-1B4C-8B80-0EFC-9FF2346373BF.rar
如果不做出來,直接存取http://miresearch.cn/uploadfile/resource/2012-05這個可以查看伺服器此目錄下的所有檔案,後來經過了apache配置使http://miresearch.cn/2012-05/8F4F5A42-1B4C-8B80-0EFC-9FF2346373BF.rar可以實現下載檔案以隱藏伺服器目錄,且http://miresearch.cn/2012-05此目錄不能直接存取。
初學者對檔案下載僅僅做了這麼點工作,請各位高手看看,有什麼好建議方案,給小弟指導下~有做過檔案下載的安全性請過來看看,指引下哦~
------解決方案--------------------
帳號密碼驗證後直接輸出檔案...
例如
PHP code
header('Content-Type: application/octet-stream');$filesize = filesize('s.png'); //獲得檔案大小header('Last-Modified: '.gmdate('D, d M Y H:i:s') . ' GMT');header('Cache-Control: no-store, no-cache, must-revalidate');header('Cache-Control: pre-check=0, post-check=0, max-age=0');header('Content-Transfer-Encoding: binary');header('Content-Encoding: none');header('Content-type: application/force-download');header('Content-length: '.$filesize);header('Content-Disposition: attachment; filename="s.png"');readfile('s.png');