NYCPHP Meetup

NYPHP.org

[nycphp-talk] Images//Pages

Adam Maccabee Trachtenberg adam at trachtenberg.com
Mon Jul 12 16:18:09 EDT 2004


On Mon, 12 Jul 2004, Daniel Convissor wrote:

> $DirHandle=opendir('.');
> while ($FileName = readdir($DirHandle)) {
>    // if file extension is .jpg, display an <img /> with it
> }

The anal side to my personality requires me to mention that this code
will fail if your directory contains a file named "0" (zero). (Hey!
It's a valid filename.)

A more robust check is:

while (($FileName = readdir($DirHandle) !== false)) {

Alternatively, if you're using PHP 5, check out the DirectoryIterator
class from SPL.

-adam

-- 
adam at trachtenberg.com
author of o'reilly's "upgrading to php 5" and "php cookbook"
avoid the holiday rush, buy your copies today!



More information about the talk mailing list