note 71083 added to function.glob

From: Date: Sat, 11 Nov 2006 03:57:35 +0000
Subject: note 71083 added to function.glob
Groups: php.notes 
Request: Send a blank email to php-notes+get-119601@lists.php.net to get a copy of this message
<? //safe_glob() by BigueNique at yahoo dot ca //Function glob() is prohibited on some servers for security reasons as stated on: //http://seclists.org/fulldisclosure/2005/Sep/0001.html //(Message "Warning: glob() has been disabled for security reasons in (script) on line (line)") //safe_glob() intends to replace glob() for simple applications //using readdir() & fnmatch() instead. //Since fnmatch() is not available on Windows or other non-POSFIX, I rely //on soywiz at php dot net fnmatch clone. //On the final hand, safe_glob() supports basic wildcards on one directory. //Supported flags: GLOB_MARK. GLOB_NOSORT, GLOB_ONLYDIR //Return false if path doesn't exist, and an empty array is no file matches the pattern function safe_glob($pattern, $flags=0) { $split=explode('/',$pattern); $match=array_pop($split); $path=implode('/',$split); if (($dir=opendir($path))!==false) { $glob=array(); while(($file=readdir($dir))!==false) { if (fnmatch($match,$file)) { if ((is_dir("$path/$file"))||(!($flags&GLOB_ONLYDIR))) { if ($flags&GLOB_MARK) $file.='/'; $glob[]=$file; } } } closedir($dir); if (!($flags&GLOB_NOSORT)) sort($glob); return $glob; } else { return false; } } //thanks to soywiz for the following function, posted on http://php.net/fnmatch //soywiz at php dot net //17-Jul-2006 10:12 //A better "fnmatch" alternative for windows that converts a fnmatch pattern into a preg one. It should work on PHP >= 4.0.0 if (!function_exists('fnmatch')) { function fnmatch($pattern, $string) { return @preg_match('/^' . strtr(addcslashes($pattern, '\\.+^$(){}=!<>|'), array('*' => '.*', '?' => '.?')) . '$/i', $string); } } ?> ---- Server IP: 194.246.101.61 Probable Submitter: 64.18.165.29 ---- Manual Page -- http://www.php.net/manual/en/function.glob.php Edit -- https://master.php.net/note/edit/71083 Del: integrated -- https://master.php.net/note/delete/71083/integrated Del: useless -- https://master.php.net/note/delete/71083/useless Del: bad code -- https://master.php.net/note/delete/71083/bad+code Del: spam -- https://master.php.net/note/delete/71083/spam Del: non-english -- https://master.php.net/note/delete/71083/non-english Del: in docs -- https://master.php.net/note/delete/71083/in+docs Del: other reasons-- https://master.php.net/note/delete/71083 Reject -- https://master.php.net/note/reject/71083 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#119601) next »