I'm looking for files in a directory. My directory pathname pattern looks like this:
TEST_1.jpg
TEST_2.jpg
TEST_3.jpg
TEST_4.jpg
twPL_1.jpg
twPL_2.jpg
twPL_3.jpg
twPL_4.jpg
so if i have an URL Parameter with localhost:8000/covers?customer=twPL. I'm getting the first two jpg's and this is working. The problem is that the URL Parameter is case sensitive. If i try to write the URL Paramater with lower case characters (...?customer=twpl) i'm getting a notice :
Notice: Undefined offset: 0
Notice: Undefined offset: 1
<?php
if(isset($_GET["customer"])) {
$customer = $_GET["customer"];
$dirs = glob("cover/".$customer."*.jpg");
$allData = glob("cover/*.jpg");
$killExt = array("cover/","_1","_2","_3","_4",".jpg");
$new_array = str_replace($killExt, "", $allData);
$arrayLowerCase = array_map('strtolower', $new_array);
// die(var_dump($dirs));
if(array_search(strtolower($customer), $arrayLowerCase) !== false){
for($i=0; $i < 2; $i++) {
echo
'<div class="cover" data-page-number="0">',
'<img class="front-modal" src="'.strtolower($dirs[$i]).'"/>',
'</div>';
}
}
}
?>
I think this causes the problem $dirs = glob("cover/".$customer."*.jpg");
how can i search in this glob function in a case insensitive way...