Jump to content

Help Modifying Code To Grab Only One File From Folder Instead Of All


Recommended Posts

$files = glob("./images/$code/*.*");
for ($i=0; $i<count($files);
$i++) { $num = $files[$i];

 

Basically Im creating a k i j j i ji like site for a friend..

 

the second page works fine and shows all the photos.. whether its 1 or 20..

 

the first page is where I need to ONLY grab one photo file per listing.

 

How do I modify this code to grab one photo ( either first in the folders or random any in the folders)

 

The names are unknown to me to just simply code it by photo names.

 

so the code above work would perfectly if I can only get one .. I tried $i=0; to $i=1; but that only takes a photo away.

 

Im assuming its changing the count to... ? ... help me out thanks!

Edited by 0o0o0

you could try chan ging from a for loop to a strait rand()

$i = rand(0, count($files));
$num = $files[$i];

 

You may need to do the count() before the rand() and asign it to it's own variable, rand() is not a function I use often, so I'm not sure what it takes as valid options.

what you sent works.. but for some reason..

 

its like this.. My first page is the LISTINGS page..

 

photo - Then my description text is here

photo - Then my description text is here

photo - Then my description text is here

BLANK - Then my description text is here

photo - Then my description text is here

BLANK - Then my description text is here

photo - Then my description text is here

BLANK - Then my description text is here

photo - Then my description text is here

photo - Then my description text is here

photo - Then my description text is here

BLANK - Then my description text is here

 

but even the ones that show up blank have photos in the folders.

 

Odd I know but some photos arnt showing up with your code. So its half right tho! which is good single photos are coming up for each description line.

cept a few are skipping.. wierd huh.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.