Wildcard in file_exists()

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jkpolsar
Forum Newbie
Posts: 1
Joined: Tue Nov 04, 2003 4:19 pm

Wildcard in file_exists()

Post by jkpolsar »

Hi all,

I just had a quick question on how I could solve this problem...

I'm creating a module for someone that will upload movies to their server. Before the upload, the script checks to see if any other similarly named movies are on the server and adds a number after the filename in order to not overwrite it (e.g. movie_1.mov, movie_2.mov, movie_3.mov, etc).

When checking it with file_exists(), I'd like to check for files with ANY extension with that name (e.g. check for movie_1.mp4, movie_1.asf, movie_1.*).

file_exists($mov_location . "/" . $mov_prefix . "_" . $move_next . ".mov");

I basically need the ".mov" above to be a wildcard.

Any help would be greatly appreciated!
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

depends on your version of php wether there is such a built-in function or not.
Take a look at http://php.net/glob
If there's no such function you have to iterate the directory's filenames yourself.
Post Reply