在这篇文章的指导下,防止PHP中的目录遍历但允许路径我试图阻止目录遍历,但是我遇到了一些奇怪的事情,首先,realpath返回了一个好的路径
$fPath = $path.$parent.'/'.$name;
//$name (the user input) in this sample is "fff", $parent is an empty string
//make sure user didn't try to traverse backwards on the basepath
$basepath = $path;
$realBase = realpath($basepath);
echo $realBase."<br/>";
//gives: /Users/me/Documents/www/gallery/php_sample/uploadedImages
$userpath = $fPath;
echo $userpath."<br/>";
//gives: /Users/me/Documents/www/gallery/php_sample/uploadedImages/fff
$realUserPath = realpath($userpath);
echo $realUserPath."<br/>";
//gives blank (an empty string).
为什么有任何想法?
就像AbraCadaver在评论中说的那样:“这仅在目录存在时才有效。要验证/清除用户提供的目录,您将需要一些规则并清理或拒绝它。”
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句