You are here: Re: My readdir and display images snippet - Thanks « PHP Programming Language « IT news, forums, messages
Re: My readdir and display images snippet - Thanks

Posted by Steve on 09/16/07 02:47

"Confused but working on it" <PostInGroups@wherever.com> wrote in message
news:2007091414504450073-PostInGroups@wherevercom...
> 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. :)

i think when i originally wrote that, it took all of about 5 minutues. ;^)

> 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... :)

you realize you don't have to have a thumb of each pic in order to generate
a thumb, right?

if you'd like, i can post a class that does this based on the actual image,
and then show how to use it in your main script.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация