Help - Search - Members - Calendar
Full Version: Showing All The Images In A Directory?
Zymic Webmaster Forums > Web Design & Development > Server Side Scripting > PHP
Gamma
I have a directory full of avatars I am allowing members to use. I don't want to get every avatar URL and place it in an HTML document. Is there a script that will show all the files in the directory?

As you can see I'm kind of new at this.


Thanks for any help!
Paradoks
Just put the images in the folder, and put upa link such as like

CODE
<a href="yoursite.com/avatars/">click here for avatars</a>

and when peopleclick it they will be taken to a page that just has all the avatars there. and it will say "Parent directory" they click that to go back to yoursite :-D not much of a script just using a folder. make sure that folder doesnt have a Index.html or .php or .asp or w.e ur using lol.
Brandon
QUOTE(Paradoks @ Mar 16 2008, 09:00 PM) *
Just put the images in the folder, and put upa link such as like

CODE
<a href="yoursite.com/avatars/">click here for avatars</a>

and when peopleclick it they will be taken to a page that just has all the avatars there. and it will say "Parent directory" they click that to go back to yoursite :-D not much of a script just using a folder. make sure that folder doesnt have a Index.html or .php or .asp or w.e ur using lol.

Sorted this ages ago wink.gif

nitsuarox
Is there any way to enable indexes with a .htaccess?
Paradoks
QUOTE(nitsuarox @ Mar 17 2008, 01:06 AM) *
Is there any way to enable indexes with a .htaccess?

Sorry. Since Zymic disabled the function the only way to use a root index folder would eb for themto enable it if it was as easy as .htaccess then people would enable the mail() function tongue.gif
Shadow Man
CODE

<?php

$path = "images/"; //path to the folder

$img_gal = scandir($path); //scandir() gets all files (and file ext) in a folder and puts them into an array

$img_count = count($img_gal) - 1; //count all the items in the array

$i = 2; //Start at 2 to skip the first 2 items ('[0] => .', '[1] => ..')

while ($i <= $img_count) { //loop tru the file

echo '<img src="'.$path.$img_gal[$i].'" /><br />';

$i++;

}

//The last 5 lines printout the array (youre files) for testing purpose only
//TEST
echo '<pre>';
print_r($img_gal); //print out the array
echo '</pre>';
///TEST

?>


this may help out
a simple way of doing it, scandir() and then loop tru tha files

NOTE: i added an extra - 1 in the $img_count becouse the last item in the array that i got
kept echo'ing my folder as last item. (I think its my localhost)
so if you use this and youre last image does not show delete the - 1

hope it helps someone
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2012 Invision Power Services, Inc.