Page 1 of 1

Array - File reading

Posted: Mon May 15, 2006 4:04 pm
by powerPT
Imagining a folder with these files:
gallery-12-1126647296_thumb.jpg
gallery-13-1126647296_thumb.jpg
gallery-13-1126647296.jpg
gallery-14-1126647296_thumb.jpg
gallery-15-1126647.jpg
gallery-15-11266.jpg
gallery-16-1126647296_thumb.jpg
gallery-17-1126647296_thumb.jpg
What I would know is how read the files with termination "_thumb.jpg" into an array. Then, with the random function and "echo", I could to show the thumbs in a site...

Thanks in advanced :D

Posted: Mon May 15, 2006 4:06 pm
by feyd

Posted: Mon May 15, 2006 4:10 pm
by powerPT
8O 8O 8O
That function is just what I will searched!!! Well, let´s go to another fase...

Thanks!

Posted: Tue May 16, 2006 5:21 am
by powerPT
Well, a problem:

With this code, the thing works:

Code: Select all

<?php
$path = "/home/xpto/phpBB2/garage/upload";

foreach (glob("$path/garage_gallery-*_thumb.jpg") as $name) {
 echo "$name <br />";
}
exit();
?>
How I interpret this, the name is the array variable. Now, I wish take some position from array by a random.
Then, to show the image.

I maked this code but don´t work:

Code: Select all

<?php
$url = "http:/www.xpto.com";
$path = "/home/xpto/phpBB2/garage/upload";

foreach (glob("$path/garage_gallery-*_thumb.jpg") as $nome) {
    $image = array_rand($nome,1);

echo "<img src=\"$path/$image \" width=\"150\" height=\"112\" />";

}
exit();
?>
This last code is wrong, is just to you take a look, to take my "ideia"

Posted: Tue May 16, 2006 5:39 am
by powerPT
Solved :lol:

Thanks