Php &引用;警告:preg_replace()[function.preg replace]:编译失败:在…中的偏移量3处没有要重复的内容;

Php &引用;警告:preg_replace()[function.preg replace]:编译失败:在…中的偏移量3处没有要重复的内容;,php,error-handling,Php,Error Handling,我搜索了其他问题,但找不到可行的解决方案。这是一个CMS程序,我尝试将文件上载到任何目录,但出现以下错误: 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

我搜索了其他问题,但找不到可行的解决方案。这是一个CMS程序,我尝试将文件上载到任何目录,但出现以下错误:

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;
        }
    }
function\u IsValidPath($Path)
{//首先检查路径是否以起始目录开始
$basePath=preg_replace(“/{1,}/”,“/”,$_SESSION['rootdirectory']./'。//导致错误的此行(1017)
$_会话[“启动目录]);
$sdPos=strpos($basePath,$Path);
如果(!是数字($sdPos))
{
$sdPos=strpos($Path,$basePath);
}
如果(是数值($sdPos)&&$sdPos==0)
{
//确保它不包含任何无效字符
如果(是数字(strpos($Path,“…”))||
(是数字(strpos($Path,“./”))||
(是数字(strpos($Path,“/”))||
(是数字(strpos($Path,“\\”))||
(是数字(strpos($Path,“../”))||
(是数字(strpos($Path,&”))||
(是数字(strpos($Path,“*”))||
(是数字(strpos($Path,“”))||
(是数字(strpos($Path,“”))||
(是数字(strpos($Path,“\?”))||
(是数字(strpos($Path,“”)))
{
返回false;
}
其他的
{
//这条路还可以
返回true;
}
}
其他的
{
返回false;
}
}
将其更改为:

$basePath = preg_replace("@/{1,}/@", "/", $_SESSION['rootdirectory'] . '/' .
 $_SESSION["startingdirectory"]);
preg\u replace
要求正则表达式由字符串中的字符分隔,以便您可以在之后指定标志,如
g
i
(我通常使用
@
)。它将
/
视为分隔符。有关更多信息,请参阅

即使如此,这段代码也没有多大意义,而且可能有更好的方法来完成它应该做的事情

/{1,}/
看起来您正在尝试匹配一个或多个空项