469,270 Members | 1,011 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,270 developers. It's quick & easy.

opening a file when you do not know the full name

I have a directory into which I upload pictures. I know the
entire file name other than the extension.

file_exists will return true when I give it a wildcard extension,
but I can't figure out the best way to determine the extension
for fopen.

I sure don't want to troll through the entire directory with
readdir.

I would appreciate suggestions.

bill
Dec 2 '06 #1
4 3248

bill wrote:
I have a directory into which I upload pictures. I know the
entire file name other than the extension.

file_exists will return true when I give it a wildcard extension,
but I can't figure out the best way to determine the extension
for fopen.

I sure don't want to troll through the entire directory with
readdir.

I would appreciate suggestions.

bill
If you use the "find" command with exec() you can get a list of files
that match your criteria. Essentially using the filename you already
know, and then a wildcard for the extension...

find /var/www/directory/pics2 -name "weddingphoto.*"

For me this outputs: /var/www/directory/pics2/weddingphoto.jpg

If you output the results into a file or into a variable, you can then
parse it for whatever is relevent to you.

find /var/www/directory/pics2 -name "weddingphoto.*" >
/var/www/directory/pics2/results.txt

Dec 2 '06 #2
..oO(bill)
>I have a directory into which I upload pictures. I know the
entire file name other than the extension.

file_exists will return true when I give it a wildcard extension,
but I can't figure out the best way to determine the extension
for fopen.
http://www.php.net/glob

Micha
Dec 3 '06 #3
Michael Fesser wrote:
.oO(bill)
I have a directory into which I upload pictures. I know the
entire file name other than the extension.

file_exists will return true when I give it a wildcard extension,
but I can't figure out the best way to determine the extension
for fopen.

http://www.php.net/glob

Micha
Not so sure that I agree using a function in an application, that
communicates with the OS via a webserver, is a better choice than
something native to the operating system, but this solution will
definitely work. Probably easier to handle the result set too.

Dec 4 '06 #4
pangea33 wrote:
Michael Fesser wrote:
>.oO(bill)
>>I have a directory into which I upload pictures. I know the
entire file name other than the extension.

file_exists will return true when I give it a wildcard extension,
but I can't figure out the best way to determine the extension
for fopen.
http://www.php.net/glob

Micha

Not so sure that I agree using a function in an application, that
communicates with the OS via a webserver, is a better choice than
something native to the operating system, but this solution will
definitely work. Probably easier to handle the result set too.
In my case where there is only one result, should work a treat.

Thanks

bill
Dec 4 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

11 posts views Thread by Ahmet AKGUN | last post: by
11 posts views Thread by aldrin | last post: by
2 posts views Thread by JohnGoogle | last post: by
185 posts views Thread by jacob navia | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.