Page 1 of 1
Existence of a picture
Posted: Fri Dec 13, 2002 10:47 am
by CrE3pZ
Hi, I'm a newbie to PHP, but I'm learning (I love it allready

)...
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
Posted: Fri Dec 13, 2002 10:54 am
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.
Posted: Fri Dec 13, 2002 10:58 am
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
Posted: Fri Dec 13, 2002 11:08 am
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.
Posted: Fri Dec 13, 2002 11:10 am
by Johnm
Posted: Fri Dec 13, 2002 11:18 am
by CrE3pZ
thx, it works! I still have to read your comment for about 10 times to understand it fully

But I think I see WHY it works, really cool. Thx
Posted: Fri Dec 13, 2002 11:19 am
by CrE3pZ
ghehe I can see clearly now
