• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

using php and an array to display thumbs

dmize

Limp Gawd
Joined
Jan 29, 2004
Messages
376
I have a dir with about 20 thumbs in it. Is there a easy way to make PhP cycle through an array and display those on a page? I have some php/js experience I just cant get my head around how to do this.

I use this to display a random pic from the dir, so i was hoping I could just add on to it to display all the images...

-------------------------------

$path = "../Photos/FP_Thumbs/";

foreach (glob($path. "*.jpg") as $imagename) {
$images[] = $imagename;
}

$image = $images[ rand(0,(count($images)-1)) ];

-----

then I just plug in $image into a <Img src> tag....

So i know I have my array loaded with all the images... im just not sure how to pull them all out....

any suggestions would be great...

thanks
D.
 
If you just wanted to display all the files in the directory (and you're sure all the files are ones you want to show ;)), why don't you just iterate through all the files in the directory and write the appropriate code to display them for each file? No need to construct an array only to go through it again, right?

Very very abstractly...
Code:
$dirHandle = opendir('...directorypath...');
while(false != ($file = readdir($dirHandle))) {
    # do what you want to
}
 
you lost me bille sorry =(

I guess the problem im having is figuring out how to take a directory with thumbnail images and write a script that will put those on in some html.

basically i dont want to have to do

<img src="blahblah">

50 times.

let alone have to worry about updating each SRC path with a new file name when I put new thumbnails into the directory.

I assumed a php array would be a good start. But i cant figure out how to extract those in the array and convert them to a <img src> tag.

ive been beating my head silly for a few days now... grrr..
 
if you already have an array of filenames, why not just do this
Code:
foreach($images as $img) {
    echo "<img src=\"$img\">";
}
 
if you already have an array of filenames, why not just do this
Code:
foreach($images as $img) {
    echo "<img src=\"$img\">";
}

worked like a charm...

wow ive been trying that on and off for 2 days but couldnt get it to work. I wasnt putting

echo "<img src=\"$img\">";

in quotes. sometimes the you look through the forest to see the tree's i guess... lol

thanks..
 
It should work without the quotes, unless the file names have spaces in them (I think)
 
No, rapid. I believe with new HTML standards you must put ALL attribute values in quotes. Another note, just to make it that much more compliant -- change that code to:

echo "<img src=\"$img\" />"

Otherwise the <img> tag has no ending tag. Although it should display without this, making your page up to standards generally increases compatibility throughout browsers and render time on a couple as well.
 
ya i actually got my brain to catch that one hahaha...

thanks for the heads up though...
 
Back
Top