You are here: Re: opening a file when you do not know the full name « PHP Programming Language « IT news, forums, messages
Re: opening a file when you do not know the full name

Posted by pangea33 on 12/02/06 23:28

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

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация