note 95901 deleted from function.file-exists by danbrown

From: Date: Thu, 28 Jan 2010 13:24:15 +0000
Subject: note 95901 deleted from function.file-exists by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-165432@lists.php.net to get a copy of this message
Note Submitter: robert irrelevant com ---- Just to take further joel atSymbol avial.com.au's routine, I had a need for a case-insensitive file_exists that would cope with the directory names also being wrongly cased. This recursive version does the trick. It also returns the actual filename as it exists on the disc, or an empty string, so that subsequent operations can locate the file. function similar_file_exists($filename) { if ($filename == "") return ""; if (file_exists($filename)) { return $filename; } $dir = dirname($filename); if (!file_exists($dir)) { if (($dir=similar_file_exists($dir)) == "") return ""; } $files = glob($dir . '/*'); $lcaseFilename = strtolower($filename); foreach($files as $file) { if (strtolower($file) == $lcaseFilename) { return $file; } } return ""; }

« previous php.notes (#165432) next »