Afficher un message
Vieux 16/09/2007, 14h06   #5
Jerry Stuckle
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: readdir() doesn't maintain order

Confused but working on it wrote:
> On 2007-09-15 09:03:24 -0700, Andy Hassall <andy@andyh.co.uk> said:
>
>> On Sat, 15 Sep 2007 08:10:46 -0700, Semi Confused
>> <PostInGroups@wherever.com>
>> wrote:
>>
>>> $dir = opendir("thumbs");
>>> //read files in the dir
>>> while (($file = readdir($dir)) !== false)
>>>
>>> Was reviewing a few of the pages I made and something seemed odd.
>>> Further investigation showed that my thumbs are not in the order of
>>> the filesystem.
>>> So it starts at pic 1370 and ends back at 1359. In reality the pics
>>> start at 1359 and end at 1424. Maybe the question is how is the file
>>> system really sorted?

>>
>> Yes.
>>
>>> I haven't tried to implement the other methods shown this week and
>>> maybe one doesn't do this?
>>> or
>>> Readdir into an array?

>>
>> Yes, or scandir() (which gives a sorted array), or glob() (which both
>> filters
>> and sorts), but in either case you may still want a different sort
>> order - in
>> particular look at natsort().
>>
>> http://php.net/scandir
>> http://php.net/glob
>> http://php.net/natsort

>
> So I kludged this together and it doesn't fail but doesn't display my
> image after I click the thumb. glob() says it searches for all pathnames
> so if the file was where the code is then the filname is the pathname. I
> think. when i mouseover I can see that the path for the image has
> "thumbs" in it as it is part of the path from blob().
>
> <?php
> foreach (glob("thumbs/*.jpg") as $file)
> echo "<a href='images/$file'><img src='$file'
> class=\"pad1em\"></a>";
> ?>
>
> How do I remove the thumbs from the link on the echo?
>


Maybe something like

str_replace('thumbs/', '', $file);

> I think you guys are messing with me.
>


And why would we do that?

> Thanks,
> Ron
>



--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
  Réponse avec citation
 
Page generated in 0,05745 seconds with 9 queries