作者guancheng (Austin)
看板PHP
标题Re: [请益] 有关目录读取问题??
时间Sun Jan 18 15:16:56 2009
我猜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
1F:推 joedenkidd :谢谢好心人,我会试看看,不过我有一个疑问,这是不 01/18 20:55
2F:→ joedenkidd :是针对档案都在download下,如果download下还有其他 01/18 20:56
3F:→ joedenkidd :目录是否也能试用呢?我会先try看看!到时候再把心得 01/18 20:57
4F:→ joedenkidd :放上来! 01/18 20:57
5F:推 joedenkidd :我试过这个方法了,这是方法应该ok,谢谢! 01/18 23:09