php - wildcard searching for filename in folder with preg_match? -
php - wildcard searching for filename in folder with preg_match? -
i've code want check if there file located in folder. every file has @ start of filename 00'.$id'-time() illustration "00226-1413203222.pdf".
i have code checking if there file id :
$id = 226; $searchpath = "files/00" . $id . "-*"; if (file_exists($searchpath)) { ... ... ...
but code don't want work, need other method this?
can u give me advices how best way?
thank you
why not utilize scandir() so
$id = "26"; $dir_path = "files"; $filesearchregex = "/^00".$id."-[0-9]*\.pdf$/"; $foundfile = array_map(function($file){ if(preg_match($filesearch, $file)) homecoming $file; }, scandir($dir_path));
php search wildcard
Comments
Post a Comment