duanjia4969 2012-08-19 22:57
浏览 56

PHP包含路径和路径分隔符混淆

I'm trying to get an opensource web application running. Its from here - https://sourceforge.net/projects/labshare-sahara/ It uses the Zend PHP framework.

My problem is with the following bit of code. It fails to find a file, and so it returns false, and the message:

"2012-08-20T00:01:08+02:00 DEBUG (7): Unable to find auth class SAHARANS_Auth_Type_Database in include path"

is outputted to the log file.


   private function _loadClass($name)
       {
            /* Find the class to load. */
            $file = implode('/', explode('_', $name)) . '.php';
            foreach (explode(PATH_SEPARATOR, get_include_path()) as $path)
            {
                $this->_logger->debug("does $path/$file exist?"); //I added this
                if (file_exists($path . PATH_SEPARATOR . $file))
                {
                    return new $name();
                }
            }

            $this->_logger->debug("Unable to find auth class $name in include path.");
            return false;
        }

To give a bit more context I got it to print some more information to the log - so it writes to the log each time round the for loop. This is the output:

2012-08-20T00:47:07+02:00 DEBUG (7): does C:\xampp\htdocs\Sahara-WI\WI\application/../library/SAHARANS/Auth/Type/Database.php exist?

2012-08-20T00:47:07+02:00 DEBUG (7): does C:\xampp\htdocs\Sahara-WI\WI\library/SAHARANS/Auth/Type/Database.php exist?

2012-08-20T00:47:07+02:00 DEBUG (7): does C:\xampp\htdocs\Sahara-WI\WI\application\models/SAHARANS/Auth/Type/Database.php exist?

2012-08-20T00:47:07+02:00 DEBUG (7): does C:\xampp\htdocs\Sahara-WI\WI\institution/SAHARANS/Auth/Type/Database.php exist?

2012-08-20T00:47:07+02:00 DEBUG (7): does ./SAHARANS/Auth/Type/Database.php exist?

2012-08-20T00:47:07+02:00 DEBUG (7): does C:\xampp\php\PEAR/SAHARANS/Auth/Type/Database.php exist?

2012-08-20T00:47:07+02:00 DEBUG (7): Unable to find auth class SAHARANS_Auth_Type_Database in include path

2012-08-20T00:47:07+02:00 DEBUG (7): does C:\xampp\htdocs\Sahara-WI\WI\application/../library/Sahara/Auth/Type/Database.php exist?

2012-08-20T00:47:07+02:00 DEBUG (7): does C:\xampp\htdocs\Sahara-WI\WI\library/Sahara/Auth/Type/Database.php exist

2012-08-20T00:47:07+02:00 DEBUG (7): does C:\xampp\htdocs\Sahara-WI\WI\application\models/Sahara/Auth/Type/Database.php exist?

Note: Database.php does exist in the models\Sahara\Auth\Type directory!

What immediately seemed strange is the interchange between '/' and '\' in the paths, but trying to force a backlash (I'm using a windows machine) didn't seem to have any affect.

Thanks in advance!

  • 写回答

3条回答 默认 最新

  • doujia1871 2012-08-19 23:15
    关注

    PATH_SEPARATOR is ; on windows, and : on other operating system. It is used to split multiple paths, not (sub)directories and file names.

    Change:

    if (file_exists($path . PATH_SEPARATOR . $file));
    

    To:

    if (file_exists($path . '/' . $file));
    

    This will work everywhere.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?
  • ¥15 matlab(相关搜索:紧聚焦)