PHP新手-我需要做一个不区分大小写的目录文件搜索


PHP Newbie - I need to do a case insensitive directory file search

<?php
//--- get all the directories
$dirname = '//10.9.0.215/images/';
//--- $dirname = 'Images';
$findme  = $_POST["ImageName"];
$dirs    = glob($dirname.'*', GLOB_ONLYDIR);
$files   = array();
echo '<img src="logo.jpg"/><br><br>';
echo '<a href="index.html">Return Home</a><br><br>';
echo "<b>--- List of Images Found ---</b><br><br>";
//--- search through each folder for the file
//--- append results to $files
foreach( $dirs as $d ) {
    $f = glob( $d .'/'. $findme );
    if( count( $f ) ) {
        $files = array_merge( $files, $f );
    }
}
if( count($files) ) {
    foreach( $files as $f ) {      
echo "<a href='{$f}'>{$f}</a><br>";
    }
} else {
    echo "Image not found.";//Tell the user nothing was found.
//--- echo '<img src="yourimagehere.jpg"/>';//Display an image, when nothing was found.
}
?>

如果你把你的样式改成这样:

$dirname = '//10.9.0.215/[Ii][Mm][Aa][Gg][Ee][Ss]/';

您应该能够匹配图像的任何大小写变化