note 90256 added to function.file-exists
| From: | joelatSymbolavial dot com dot au at osu1 dot php dot net | Date: | Mon, 13 Apr 2009 01:52:49 +0000 |
| Subject: | note 90256 added to function.file-exists | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-153132@lists.php.net to get a copy of this message | ||
I wanted to check for the existance of a file with the same name, but disregarding case. Here is
what I came up with:
<?php
/**
* Alternative to file_exists() that will also return true if a file exists
* with the same name in a different case.
* eg. say there exists a file /path/product.class.php
* file_exists('/path/Product.class.php')
* => false
* similar_file_exists('/path/Product.class.php')
* => true
*/
function similar_file_exists($filename) {
if (file_exists($filename)) {
return true;
}
$dir = dirname($filename);
$files = glob($dir . '/*');
$lcaseFilename = strtolower($filename);
foreach($files as $file) {
if (strtolower($file) == $lcaseFilename) {
return true;
}
}
return false;
}
?>
----
Server IP: 117.55.229.1
Probable Submitter: 60.242.101.153
----
Manual Page -- http://www.php.net/manual/en/function.file-exists.php
Edit -- https://master.php.net/note/edit/90256
Del: integrated -- https://master.php.net/note/delete/90256/integrated
Del: useless -- https://master.php.net/note/delete/90256/useless
Del: bad code -- https://master.php.net/note/delete/90256/bad+code
Del: spam -- https://master.php.net/note/delete/90256/spam
Del: non-english -- https://master.php.net/note/delete/90256/non-english
Del: in docs -- https://master.php.net/note/delete/90256/in+docs
Del: other reasons-- https://master.php.net/note/delete/90256
Reject -- https://master.php.net/note/reject/90256
Search -- https://master.php.net/manage/user-notes.php