我的数据库表上有一些行在目录上没有同步。
前任。在我的桌子上我有
image.png
但在我的目录上我有
image.PNG
现在,我有问题要检查是否
file_exist
因为区分大小写。我无法选择手动同步目录中的数据库和文件的选项,因为它太多了。
我可以知道如何使用忽略文件类型敏感性的 file_exist 吗?
我的数据库表上有一些行在目录上没有同步。
前任。在我的桌子上我有
image.png
但在我的目录上我有
image.PNG
现在,我有问题要检查是否
file_exist
因为区分大小写。我无法选择手动同步目录中的数据库和文件的选项,因为它太多了。
我可以知道如何使用忽略文件类型敏感性的 file_exist 吗?
有关更通用的解决方案,请参阅 php 文档中的注释:
它提供了这个版本的功能:
/**
* Alternative to file_exists() that will also return true if a file exists
* with the same name in a different case.
* eg. say there exists a file /path/product.class.php
* file_exists('/path/Product.class.php')
* => false
* similar_file_exists('/path/Product.class.php')
* => true
*/
function similar_file_exists($filename) {
if (file_exists($filename)) {
return true;
}
$dir = dirname($filename);
$files = glob($dir . '/*');
$lcaseFilename = strtolower($filename);
foreach($files as $file) {
if (strtolower($file) == $lcaseFilename) {
return true;
}
}
return false;
}
创建一个检查两个扩展的函数并直接使用它而不是 file_exist。
我认为,您的根本原因是由于以下原因 -
如果您的数据库有“image.png”并且在目录“image.PNG”中,则意味着您的插入查询存在问题。
这两个地方必须相同。最好建议以小写形式存储文件名,因为 Linux 系统区分大小写。