proper usage of glob()
Is this the correct way to us glob() i'm trying to do a case insensitive search for the folder TestFolder on the server.
$chid = "testFoLdER";
$dirchk2 = "/temp/files/" . glob('".$chid."') . "/" . $data[1] . ".doc";
@code_burgar I made these changes to apply to the example code_burgar showed me. is this correct? what i'm trying to do here is what ever globistr find for casing, rename the folder to lowercase.
$chid = (strtolower($_POST['chid']));
$findbatch = globistr($chid);
$results = glob($findbatch);
if ( !empty($results) ) {
$result = $results[0];
rename("/temp/files/" . $results . "/", "/temp/files/" . strtolower($chid) . "/");
}
else
{
$missing_dir = 'Folder containing files, Not Found: ' . $chid . "\r";
$errfile = fopen("/rec/" . $chid . "-errlog.txt", "a");
fwrite($errfile, $missing_d开发者_运维问答ir . "\n");
fclose($errfile);
exit();
}
That is most definitely not the way to use glob()
. glob()
returns an array and you are trying to use it in string concatenation.
As Pekka pointed out, PHP man page for glob has some case-insensitive example code.
What you are looking for basically is something along these lines (globistr() comes from PHP man page comments):
$chid = globistr("testFoLdER");
$results = glob($chid);
if ( !empty($results) ) {
$result = $results[0];
$dirchk2 = "/temp/files/" . $result . "/" . $data[1] . ".doc";
} else {
echo('Not found');
}
As workaround you can search all folder inside /temp/files/ that contain $data[1]. '.doc' file and then loop through results to make case-insensitive check if path contains your folder.
$file = "/temp/files/*/".$data[1].".doc";
$locations = glob($file);
$found = false;
foreach($locations as $l){
if(stripos($l,'/testfolder/') !== false){
$found = $l;
break;
}
}
精彩评论