![]() |
|
|
|||||||
![]() |
|
|
Thread Tools | Rate Thread |
|
|
PM User | #1 |
|
Administrator ![]() ![]() Join Date: Mar 2002
Location: North America
Posts: 2,418
Thanks: 1
Thanked 13 Times in 13 Posts
![]() |
Retrieve and output certain files within a directory
I thought I'd kick start this forum by posting a PHP code I put together yesterday to allow me to retrieve all files within a directory, limited by file types (ie: images only). I needed it to dynamically populate a JavaScript slideshow with all images from a directory without maually specifying each image. Here it is:
PHP Code:
backgr10.jpg backgr11.jpg backgr12.jpg backgr13.jpg backgr14.jpg backgr15.jpg backgr16.jpg Reference(s) used: http://ca.php.net/manual/en/function.readdir.php
__________________
- George - JavaScript Kit- JavaScript tutorials and 400+ scripts! - JavaScript Reference- JavaScript reference you can relate to. Last edited by WA; 11-08-2005 at 08:45 PM.. |
|
|
|
|
|
PM User | #2 |
|
Senior Coder ![]() Join Date: Jan 2004
Posts: 2,340
Thanks: 1
Thanked 7 Times in 7 Posts
![]() |
Under that, a file such as blah.jpeg.html would show up.
Try replacing PHP Code:
PHP Code:
__________________
Geoffrey Sneddon Last edited by gsnedders; 11-06-2005 at 12:03 PM.. |
|
|
|
|
|
PM User | #3 |
|
Sensei ![]() ![]() Join Date: Aug 2003
Location: One step ahead of you.
Posts: 2,815
Thanks: 0
Thanked 3 Times in 3 Posts
![]() |
How about changing
PHP Code:
PHP Code:
__________________
I'm not sure if this was any help, but I hope it didn't make you stupider. Experience is something you get just after you really need it. PHP Installation Guide Feedback welcome. |
|
|
|
|
|
PM User | #4 |
|
Administrator ![]() ![]() Join Date: Mar 2002
Location: North America
Posts: 2,418
Thanks: 1
Thanked 13 Times in 13 Posts
![]() |
Hi Error 404:
You read my mind. that Using regular expressions to properly detect a valid image format was one of the things I knew I had to add. Thanks for the modification.
__________________
- George - JavaScript Kit- JavaScript tutorials and 400+ scripts! - JavaScript Reference- JavaScript reference you can relate to. |
|
|
|
|
|
PM User | #5 |
|
Administrator ![]() ![]() Join Date: Mar 2002
Location: North America
Posts: 2,418
Thanks: 1
Thanked 13 Times in 13 Posts
![]() |
I've just edited the code above to use regular expressions to better filter out a valid image based on its extension.
__________________
- George - JavaScript Kit- JavaScript tutorials and 400+ scripts! - JavaScript Reference- JavaScript reference you can relate to. |
|
|
|
|
|
PM User | #7 |
|
Senior Coder ![]() Join Date: Jan 2004
Posts: 2,340
Thanks: 1
Thanked 7 Times in 7 Posts
![]() |
PHP Code:
__________________
Geoffrey Sneddon |
|
|
|
|
|
PM User | #9 |
|
Regular Coder ![]() Join Date: Jul 2004
Location: Lynnwood, Washington, US
Posts: 824
Thanks: 2
Thanked 1 Time in 1 Post
![]() |
Also
PHP Code:
PHP Code:
That might not be the correct regular expression, I am horrible with it, but I used that for my version that I used.
__________________
Check out TV Shack, and get entertained! |
|
|
|
![]() |
| Bookmarks |
| Thread Tools | |
| Rate This Thread | |
|
|