acctman
acctman

Reputation: 4349

Checking to see if file exist in multiple locations

I have a two part question...

  1. For my file check I need to look to see if the file is present in $filechk or $dirchk.

  2. How can I use a wildcard on the file extension $filename.* when doing a file check? I'm using is_file because I read that it's twice as fast when checking if a file exists.

code

$filechk1 = "/temp/files/" . $data[0] . ".doc";
$filechk2 = "/temp/files/" . $data[1] . ".doc";
$dirchk1 = "/temp/files/" . $IDname . $data[0] . ".doc";
$dirchk2 = "/temp/files/" . $IDname . $data[1] . ".doc";            
if(is_file($filechk1) && ($filechk2)){
   ...
}
else { ... }

Upvotes: 0

Views: 736

Answers (2)

DreamWave
DreamWave

Reputation: 1940

you should get a list of all of the files in the directory and then check the file extensions - is_file is for a single file only.

Upvotes: 1

Pekka
Pekka

Reputation: 449525

To check a number of files, just do a separate is_file() or file_exists() - the speed difference between the two is hardly relevant if you're doing this on one or two files.

For a wildcard search, do a glob().

$files = glob("/path/to/directory/*.doc");
print_r($files); 

Upvotes: 1

Related Questions