我已經搜索了其他問題,但找不到可行的解決方案。這是一個CMS程序,我試着將文件上傳到任意目錄,並正在以下錯誤:「警告:preg_replace()[function.preg-replace]:編譯失敗:沒有重複的偏移量3在...」
Warning: preg_replace() [function.preg-replace]: Compilation failed: nothing to repeat at offset 3 in /home/...on line 1017
下面是代碼,有什麼建議?:
function _IsValidPath($Path)
{ // First check if the path starts with the starting directory
$basePath = preg_replace("/{1,}/", "/", $_SESSION['rootdirectory'] . '/' . // this line (1017) causing the error
$_SESSION["startingdirectory"]);
$sdPos = strpos($basePath, $Path);
if (!is_numeric($sdPos))
{
$sdPos = strpos($Path, $basePath);
}
if(is_numeric($sdPos) && $sdPos == 0)
{
// Make sure it doesn't contain any invalid characters
if(is_numeric(strpos($Path, "..")) ||
(is_numeric(strpos($Path, "./"))) ||
(is_numeric(strpos($Path, "//"))) ||
(is_numeric(strpos($Path, "\\"))) ||
(is_numeric(strpos($Path, "../"))) ||
(is_numeric(strpos($Path, "&"))) ||
(is_numeric(strpos($Path, "*"))) ||
(is_numeric(strpos($Path, " "))) ||
(is_numeric(strpos($Path, "'"))) ||
(is_numeric(strpos($Path, "\?"))) ||
(is_numeric(strpos($Path,"<"))) ||
(is_numeric(strpos($Path, ">"))))
{
return false;
}
else
{
// The path is OK
return true;
}
}
else
{
return false;
}
}
完美。非常感謝@ jnylen。 – csirgo