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

时间:2016-09-07 21:12:53

标签: php

<?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.
}

?>

1 个答案:

答案 0 :(得分:0)

如果您将模式更改为:

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

你应该可以填充图像

的任何案例变体