searching a directory for a image

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
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

searching a directory for a image

Post by penguinboy »

okay i need help searching for an image

i'm trying to search with an "*"
but its not working

basically i'm looking for any file that ends in
_$_GET[DNID]_p1

so it could be

1_2_p1
2_2_p1
89_2_p1
bob_2_p1
smelly_bob_2_p1


$img1 = "*_$_GET[DNID]_p1";


if(file_exists("$img1"))
{print("<a href=\"javascript:popUp('$img1')\">&nbsp;&nbsp;<img src='$img1' width='150' height='150' border=0></a>");}

else
{print("&nbsp;&nbsp;<a href=\"javascript:popUp('up.php?P=p1&W=def')\">Upload Image 1</a>&nbsp;&nbsp;");}
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

AFAIK you can't use wildcards like '*' with file_exists().

Mac
superwormy
Forum Commoner
Posts: 67
Joined: Fri Oct 04, 2002 9:25 am
Location: CT

Post by superwormy »

Are you on a Linux server? You could use something like this:

shell_exec ("find ... [filename and params here, see man find under linux]");


And then print those results. Might also be worth looking into putting info into database, ie name the images just by the record Index in the database, then search the database.
User avatar
twigletmac
Her Royal Site Adminness
Posts: 5371
Joined: Tue Apr 23, 2002 2:21 am
Location: Essex, UK

Post by twigletmac »

You could also loop through the directory and use a regular expression to find matches:

http://www.php.net/manual/en/ref.dir.php
http://www.php.net/manual/en/ref.pcre.php

Mac
Post Reply