|
Posted by Confused but working on it on 09/14/07 21:50
On 2007-09-13 09:07:17 -0700, "Steve" <no.one@example.com> said:
>
> "Confused but working on it" <PostInGroups@wherever.com> wrote in
> message news:2007091209500416807-PostInGroups@wherevercom...
>> Just wanted to say thanks for the posts helping me make ths work. Added
>> a few comments and after the readdir used a pattern match to test for
>> .jpg, and seems to work fine on my test setup. Maybe I should test for
>> gif, tiff, and png... Anyway, here's the code:
>
> ok, so i've got time on my hands...after re-reading posts today, i'm on
> this one again. here's something that will allow you to list any file
> you want either filtering by extension or just getting everything. i've
> been using the function below since glob became availabe in php.
> beneath it, i wrapped up some pseudo-testing code so you could see how
> the function can be called and what each param will generate for you.
>
> have fun. ;^)
>
> <?
> function listFiles($path, $extension = array(), $combine = false)
> {
> if (!chdir($path)){ return array(); }
> if (!$extension){ $extension = array('*'); }
> if (!is_array($extension)){ $extension = array($extension); }
> $extensions = '*.{' . implode(',', $extension) . '}';
> $files = glob($extensions, GLOB_BRACE);
> if (!$files){ return array(); }
> $list = array();
> foreach ($files as $file)
> {
> $list[] = ($combine ? $path : '') . $file;
> }
> return $list;
> }
>
> // sampling output
> function beautify($html)
> {
> $html = str_replace(' :: Array', '', $html);
> return $html;
> }
> ob_start('beautify');
> // end sample
>
> // test the function
> $path = 'c:/inetpub/wwwroot/images';
> $extensions = array('jpg', 'gif', 'tif?');
>
> echo '<pre>directory listing for "' . $path . '"</pre>';
>
> $images = listFiles($path);
> echo '<pre>no filter, no directory :: ' . print_r($images, true) . '</pre>';
>
> $images = listFiles($path, null, true);
> echo '<pre>no filter :: ' . print_r($images, true) . '</pre>';
>
> $images = listFiles($path, 'jpg', true);
> echo '<pre>single filter :: ' . print_r($images, true) . '</pre>';
>
> $images = listFiles($path, $extensions, true);
> echo '<pre>multiple filter :: ' . print_r($images, true) . '</pre>';
> ?>
Steve,
Wow, way too much time on your hands. :)
My first goal was to get my pics to display, then get rid of the . and
..., now I will fix the code to the example you gave before if you say
it's faster. Then,(light drumroll...), I want to read everything in
thumbs and create my output so I get the thumbto link to a larger pic
in images. Some sort of anchor tag thing. THAT would be cool to me.
Then I can rewrite about 20 pages, export 20 albums as thumbs and 20
albums as images... :)
I'm going to make my anchor tag...
thx..ron
[Back to original message]
|