Re: [請益] 有關目錄讀取問題??

看板PHP作者 (Austin)時間17年前 (2009/01/18 15:16), 編輯推噓3(303)
留言6則, 2人參與, 最新討論串2/2 (看更多)
我猜download.php裡應該就是類似readfile($_GET['file']); 先不說你的bug,他可能還會有些問題 1. php讀檔是依檔案系統的路徑,跟apache的虛擬目錄應該沒關係吧 2. 這樣傳絕對路徑去讀檔太危險了喔@@ $_GET['file']原本是傳絕對路改傳相對路徑 例如:http://127.0.0.1/download.php?file=test.txt 程式碼你可以改成如下: <?php $path = 'd:/download/'; $file = $path.$_GET['file']; if (file_exists($file)) { header('Content-Description: File Transfer'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename='.basename($file)); 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; } else { echo 'File not exist!'; } ?> -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 123.240.2.13

01/18 20:55, , 1F
謝謝好心人,我會試看看,不過我有一個疑問,這是不
01/18 20:55, 1F

01/18 20:56, , 2F
是針對檔案都在download下,如果download下還有其他
01/18 20:56, 2F

01/18 20:57, , 3F
目錄是否也能試用呢?我會先try看看!到時候再把心得
01/18 20:57, 3F

01/18 20:57, , 4F
放上來!
01/18 20:57, 4F

01/18 23:09, , 5F
我試過這個方法了,這是方法應該ok,謝謝!
01/18 23:09, 5F

01/19 00:50, , 6F
01/19 00:50, 6F
文章代碼(AID): #19SjTfsG (PHP)
文章代碼(AID): #19SjTfsG (PHP)