Forum Moderators: coopster
i know how to find out how many there are with count()
i know how to display it if it's like this name[1]
so if you can so me how to make it put the name of each file in name[1] name[2]
than that is all i need to know
First, loop through your folder and assign images to an array:
$pictures = array();
$folder = opendir("pictures/");
while ($read = readdir($folder))
{
if ($read!= "." && $read!= "..")
{
$pictures[] = $read;
}
}closedir($folder);
There are <?php echo count($pictures);?> pictures.
Then use a for loop for retrieve them. You can also use a foreach loop if you want, but for loops are more fun. :)
if (!empty($pictures))
{for ($i=0; $i<count($pictures); $i++)
{
echo $pictures[$i]."<br>";
}}
Or you can access them individually. Only recommended if you know how many there are or else you will get a undefined offset error.
echo $pictures[1];
echo $pictures[2];
Finally, view the contents of your array like this:
print_r($pictures)
dc
$path = "directory/path";
$files = glob($path.'/*.*');
echo '<pre>';
print_r($files);
echo '</pre>';
echo '<br/><br/>';
$num_files = count($files);
echo 'There are '.$num_files.' in this directory: '.$path;
If you don't like this solution, take a look at readdir [us3.php.net].
Good luck :)
[edit]
Seems like I'm slowing down on my typing ;)
[/edit]
it is not outputting in order
can some make it work
this is my script
$file = glob("Pictures-Thumbnails".'/*.*');
sort (natsort($file));
[edited by: MrGecko at 6:15 pm (utc) on Nov. 16, 2006]
<?
$do = isset($_REQUEST['do'])? $_REQUEST['do'] : 1;
switch ($do) {
case "Picture":
$file = glob("Pictures-Images/*.jpg");
natsort($file);
print '<pre>'; print_r($file); print '</pre>'; exit;
$Picture = isset($_REQUEST['Picture'])? $_REQUEST['Picture'] : 1;
?>