note 95901 added to function.file-exists
| From: | robertirrelevantcom at osu1 dot php dot net | Date: | Wed, 27 Jan 2010 23:28:42 +0000 |
| Subject: | note 95901 added to function.file-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-165392@lists.php.net to get a copy of this message | ||
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 "";
}
----
Server IP: 69.147.83.197
Probable Submitter: 87.81.12.15
----
Manual Page -- http://www.php.net/manual/en/function.file-exists.php
Edit -- https://master.php.net/note/edit/95901
Del: integrated -- https://master.php.net/note/delete/95901/integrated
Del: useless -- https://master.php.net/note/delete/95901/useless
Del: bad code -- https://master.php.net/note/delete/95901/bad+code
Del: spam -- https://master.php.net/note/delete/95901/spam
Del: non-english -- https://master.php.net/note/delete/95901/non-english
Del: in docs -- https://master.php.net/note/delete/95901/in+docs
Del: other reasons-- https://master.php.net/note/delete/95901
Reject -- https://master.php.net/note/reject/95901
Search -- https://master.php.net/manage/user-notes.php