你可以试验这段代码,我只留下了几个 TODO 步骤(对不起!没有时间......而且它太大了,不能作为评论)你可以完成。您将此代码放在 index.php 文件的开头,每次包含失败时都会调用正确的文件名。
您必须单独测试它,因为它从 php 返回的警告中获取文件名。我的 php 版本返回括号中的文件名不知道你的。测试代码,看看它是如何工作的。
<?PHP
/*****************put this at the very top*********************************/
$flag=2;
function correctFileName($incorrectFileName)
{
//directory and file to look at/for
$dirToLookAt = dirname($incorrectFileName);
$fileToLookFor = basename($incorrectFileName);
//get all .php files
$files = array(); $directory = opendir($dirToLookAt );
while($item = readdir($directory))
if(is_string(strstr($item,'.php')))
$files[] = $item;
//to do
/*
loop through the $files array and to
a case insensitive search for $incorrectFileName
if you find one then rename the file you found to $incorrectFileName
then break the loop
*/
}
//error handler function
function customError($errno, $errstr)
{
global $flag;
//find the file name
if($errno==2 and (($flag%2)==0))
{
//this will allow to enter only once per time
$flag++;
//get the file name
$start = strpos($errstr, '(') +1;//7
$length = strpos($errstr, ')') - $start ;//10
correctFileName(substr($errstr, $start ,$length));
}
}
//set error handler
set_error_handler("customError");
/*****************************************************************/
//trigger error
include 'c:\www\home\122221.php';
?>
代码还假设目录部分名称是正确的!否则你也必须管理它。