File Listing in PHP?

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
Dm7
Forum Commoner
Posts: 67
Joined: Sat Oct 08, 2005 9:16 pm
Location: USA

File Listing in PHP?

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
Dm7
Forum Commoner
Posts: 67
Joined: Sat Oct 08, 2005 9:16 pm
Location: USA

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

if they are actual constants, they exist everywhere, automatically
Dm7
Forum Commoner
Posts: 67
Joined: Sat Oct 08, 2005 9:16 pm
Location: USA

Post 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
User avatar
Jenk
DevNet Master
Posts: 3587
Joined: Mon Sep 19, 2005 6:24 am
Location: London

Post by Jenk »

You will need to ensure that the script that defines them is included.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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! :)
Dm7
Forum Commoner
Posts: 67
Joined: Sat Oct 08, 2005 9:16 pm
Location: USA

Post 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. :D Thanks :D
foobar
Forum Regular
Posts: 613
Joined: Wed Sep 28, 2005 10:08 am

Post 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.
Post Reply