Proper Use of glob ()

This is the right way for us glob () I'm trying to make case insensitive for the TestFolder folder on the server.

$chid = "testFoLdER"; $dirchk2 = "/temp/files/" . glob('".$chid."') . "/" . $data[1] . ".doc"; 

@code_burgar I applied these changes to an example that showed me burgar_code. It's right? what I'm trying to do here is what globistr ever finds for a shell, 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_dir . "\n"); fclose($errfile); exit(); } 
+4
source share
2 answers

This is definitely not a way to use glob() . glob() returns an array, and you are trying to use it in string concatenation.

As Pekka pointed out, the PHP manual page for glob has an example of case-insensitive code.

You are basically looking for something like that (globistr () comes from comments on the PHP man page):

 $chid = globistr("testFoLdER"); $results = glob($chid); if ( !empty($results) ) { $result = $results[0]; $dirchk2 = "/temp/files/" . $result . "/" . $data[1] . ".doc"; } else { echo('Not found'); } 
+1
source

As a workaround, you can search the entire folder inside / temp / files / containing $ data [1]. '.doc' and then swipe through the results to check case if the 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; } } 
+1
source

All Articles