Array - File reading

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
powerPT
Forum Newbie
Posts: 14
Joined: Tue Apr 04, 2006 2:25 pm
Location: Portugal

Array - File reading

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

powerPT
Forum Newbie
Posts: 14
Joined: Tue Apr 04, 2006 2:25 pm
Location: Portugal

Post by powerPT »

8O 8O 8O
That function is just what I will searched!!! Well, let´s go to another fase...

Thanks!
powerPT
Forum Newbie
Posts: 14
Joined: Tue Apr 04, 2006 2:25 pm
Location: Portugal

Post 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"
powerPT
Forum Newbie
Posts: 14
Joined: Tue Apr 04, 2006 2:25 pm
Location: Portugal

Post by powerPT »

Solved :lol:

Thanks
Post Reply