How to find the path of a specific file?

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
Ghe
Forum Newbie
Posts: 2
Joined: Wed Jun 11, 2008 8:02 pm

How to find the path of a specific file?

Post by Ghe »

Good Day to all,

Ahm, does anyone here know how can i make a function that get the filepath of a specific file?

I want to create a function like this:
- getFilePath('A_file_with_an_unknown_path.inc');
then the function will return the path of the file with an unknown path/directory.

Is this possible? If not, can anyone tell me how can I be able to include a file with an unknown filepath/directory?

- require_once('???/???/???/A_file_with_an_unknown_path.inc');

Please help.

Thank you in advance.
User avatar
superdezign
DevNet Master
Posts: 4135
Joined: Sat Jan 20, 2007 11:06 pm

Re: How to find the path of a specific file?

Post by superdezign »

The only way to do this is to know the path and directory.
I have no idea why you would want to do this, or how you would go about finding a random file in a file system, but if you know the location of the file in relativity to the file that is including it, using dirname() in combination with the __FILE__ constant can give you the current directory.
hansford
Forum Commoner
Posts: 91
Joined: Mon May 26, 2008 12:38 am

Re: How to find the path of a specific file?

Post by hansford »

or you could write an entire program for searching all of the dir and files on your server. Sounds like alot of work to me.
Ghe
Forum Newbie
Posts: 2
Joined: Wed Jun 11, 2008 8:02 pm

Re: How to find the path of a specific file?

Post by Ghe »

Oh, i see, thank you for the reply.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Re: How to find the path of a specific file?

Post by pickle »

You could use getcwd() to get your current directory, then tack on the part of the filename you know, then run that through realpath().
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Post Reply