Re: [請益] 有關目錄讀取問題??
我猜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
01/18 20:56, 2F
→
01/18 20:57, , 3F
01/18 20:57, 3F
→
01/18 20:57, , 4F
01/18 20:57, 4F
推
01/18 23:09, , 5F
01/18 23:09, 5F
推
01/19 00:50, , 6F
01/19 00:50, 6F
討論串 (同標題文章)
完整討論串 (本文為第 2 之 2 篇):
PHP 近期熱門文章
PTT數位生活區 即時熱門文章
0
18