Page 1 of 1
File Listing in PHP?
Posted: Thu Oct 20, 2005 8:28 pm
by Dm7
How do you list certain files in php? Like it looks in a directory and lists all files that ends with *.jpg (NOT *tb.jpg... need to restrict that). So I could use that array or whatever to perform image resizing of all original images into thumbnail with a loop function... the problem is, I have absolutely no idea how to do it. Anybody has an idea?
Posted: Thu Oct 20, 2005 8:31 pm
by feyd
you'd have to get a file list (
glob() and
opendir() can do this) for advanced logic like exclusion, you need to analyze the filenames returned.
Posted: Sat Oct 22, 2005 5:46 pm
by Dm7
Other question that has to be related to this script project since I'm making a function for thumbnails so when I use loop and files...
I have MAX_WIDTH, MAX_HEIGHT, and ROUNDED_CORNER defined... can I put it in function? Like
Code: Select all
global MAX_WIDTH, MAX_HEIGHT, ROUNDED_CORNER, $file, $blah;
Or will it generate an error?
Posted: Sat Oct 22, 2005 5:50 pm
by feyd
if they are actual constants, they exist everywhere, automatically
Posted: Sat Oct 22, 2005 5:52 pm
by Dm7
ok so define(MAX_WIDTH, '150'); would just work in function automatically -- not like variables do.. like they have to be global-ized in function to work?
.. wait... if I defined that in a file and have a script in other page.. and I don't refer it to that file... it would still work? :O
Posted: Sat Oct 22, 2005 5:58 pm
by Jenk
You will need to ensure that the script that defines them is included.
Posted: Sat Oct 22, 2005 6:00 pm
by feyd
the define() call must be run for each page request unless you're doing some unusual php trickery.. and remember to quote the first argument as it's not a constant yet!

Posted: Sat Oct 22, 2005 6:02 pm
by Dm7
lol i just wanted to make sure because you made it sound like once it's defined, it's not needed to be referred.

Ok now I understand.

Thanks

Posted: Sun Oct 23, 2005 6:48 am
by foobar
Here's a neat script by
Webmonkey Ash that lists files in a directory, as well as showing thumbnails for images, and other cool stuff.