我正在用PHP实现一个简单的目录列表脚本。
echo 故意否定结果。
echo
$f = $_GET["f"]; if(! $f) { $f = "/"; } // make sure $f is safe $farr = explode("/",$f); $unsafe = false; foreach($farr as $farre) { // protect against directory traversal if(strpos($farre,"..") != false) { $unsafe = true; break; } if(end($farr) != $farre) { // make sure no dots are present (except after the last slash in the file path) if(strpos($farre,".") != false) { $unsafe = true; break; } } }
可能是 realpath()
realpath()
realpath() 展开所有符号链接 并解析对 '/./' '/../' '/' 小说中的人物 输入路径,并返回
'/./'
'/../'
'/'