Web Hosting Talk







View Full Version : Looking for a PHP function..


Joshua44
11-12-2002, 03:34 PM
I need a PHP function the sees if a file exists, within a certain pattern;

I looked at PHP.net and they have glob() and another function, but neither work... :bawling: help pls? Thanks.

Rich2k
11-12-2002, 04:48 PM
It's a function called file_exists()

http://www.php.net/manual/en/function.file-exists.php

Joshua44
11-13-2002, 09:21 AM
uh.... sorry if I didn't make myself clear... I need to use it with foreach(). Foreach() can't use file_exists().

MarkIL
11-13-2002, 06:05 PM
Umm.


$dir = opendir('.') or die("Couldn't open directory.");
$pat = "/\.php$/i";
while(($f=readdir($dir))!==false)
{
if ($f=='.'||$f=='..') continue;
if (preg_match($pat,$f)) printf("%s\n",$f);
}
closedir($dir);

Joshua44
11-13-2002, 08:05 PM
TIGHT!!! Thanks :D