gpt4 book ai didi

php - PHP 的问题包含在区分大小写的文件系统上

转载 作者:可可西里 更新时间:2023-11-01 00:03:46 25 4
gpt4 key购买 nike

我在 Windows 中构建了一个 PHP 项目,如您所知,在 Windows 中 fun.php 和 Fun.php 相同,但在 Linux 中不同。
Q1-> 由于我的项目将在 Linux 中运行 如何解决此问题 [文件名错误]?
Q2-> 如果确切的文件名不存在,我需要显示错误!怎么做?

例子

我在 template.phprender.php
中有这 2 个 PHP 文件render.php

代码
include 'Template.php';

我想得到一个警告,这样我就可以解决这个问题 [这不会在 Windows 中产生问题,但在 Linux 中]

最佳答案

好吧,如果我处于那种情况,我会写一个包装器包括:

function warned_include($file)
{
if( defined( 'DEBUG_ENV' ) ) // define this somewhere else while in dev.
{
foreach( explode( PATH_SEPARATOR, get_include_path() ) as $path )
{
// make sure the / is replaced with the OS native DIRECTORY_SEPARATOR
$fullPath = str_replace($path .DIRECTORY_SEPARATOR.$file, '/', DIRECTORY_SEPARATOR);
if( is_file( $fullPath ) )
{
$spl = new SplFileInfo( $fullPath );
if( $spl->getPathname() != $fullPath )
{
echo 'case sensitivity mismatch for ' . $spl->getPathname();
}
break;
}
}
}
include $file;
}

我没有机会对其进行测试,但 SplFileInfo 从操作系统获取路径名,这意味着它在 Windows 中应该具有正确的大小写敏感性。

关于php - PHP 的问题包含在区分大小写的文件系统上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6475931/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com