Existence of a picture

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
CrE3pZ
Forum Newbie
Posts: 6
Joined: Fri Dec 13, 2002 10:47 am

Existence of a picture

Post by CrE3pZ »

Hi, I'm a newbie to PHP, but I'm learning (I love it allready 8) )...

I wanted to build a script that checks a directory for certain JPG buttons. Is it possible to make the script to look if (for example) the JPG button is present, if not the JPG story turns into a story of tables?

GrtZ
CrE3pZ
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post by nathus »

you can use the file_exists(filename) function. it takes a file name as an argument and returns true if it finds it, or false if it doesn't.
CrE3pZ
Forum Newbie
Posts: 6
Joined: Fri Dec 13, 2002 10:47 am

Post by CrE3pZ »

Thx!

Now there's one problem left, I need to filter a string down to the last dot ( . ), then remove everything behind the dot and replace it with JPG
User avatar
nathus
Forum Commoner
Posts: 49
Joined: Thu Dec 12, 2002 6:23 pm

Post by nathus »

Code: Select all

$a = explode(".", $string);
$a[sizeof($a)-1] = "jpg";
$file = implode(".", $a);
makes an array $a, fills it with the pieces of the string that are seperated by a period then replaces last element of the array (whatever came after the last period) with jpg. finally rebuilds the string as $file seperating each element of the array by a period.
User avatar
Johnm
Forum Contributor
Posts: 344
Joined: Mon May 13, 2002 12:05 pm
Location: Michigan, USA
Contact:

Post by Johnm »

CrE3pZ
Forum Newbie
Posts: 6
Joined: Fri Dec 13, 2002 10:47 am

Post by CrE3pZ »

thx, it works! I still have to read your comment for about 10 times to understand it fully :D But I think I see WHY it works, really cool. Thx
CrE3pZ
Forum Newbie
Posts: 6
Joined: Fri Dec 13, 2002 10:47 am

Post by CrE3pZ »

ghehe I can see clearly now :D
Post Reply