Question: its more to a architecture related question, sorry if i ask in the wrong stack.

do they put them in a large pile im a folder ?
like

> 
> $uid.$md5(random).$name save in one
>  folder
> 
> 
> 

```
folder/5231.124wdadace123214.arandomname.jpg
folder/42.15125dawdaowdaw232.arandom2name.png
folder/etc

```

or

> 
> $uid/$md5(random).$name
> 
> 
> 

```
5231(uid)/12421adwawda2321.arandomname.jpg
42/15125awdawdwadwa232.arandom2name.png
etc/2323awdwadwadaw.logo.png

```

what im thinking here is the second one is better?  

**because at windows i have a lot of pics in one folder**  

and yes it takes time to open it.

do you guys have any idea how they keep the files ?

Answer: 
I wrote a function for my sites that converts user ids into a two level subdirectory hierarchy that limits subdirectories to 1000 at each level.

```
function get_image_dir($gid) {
    $d = str_split(str_pad($gid, 6, "0", STR_PAD_LEFT), 3);
    $wdir = "/images/members/" . $d[0] . "/" . $d[1] . "/" . $gid;
    return $wdir;
}

```

(I actually add a third level with the raw user id to handle the rollover at 1,000,000.

```
/images/members/000/001/1
/images/members/000/002/2
...
/images/members/999/999/999999
/images/members/000/000/1000000
/images/members/000/001/1000001

```

Within those subdirectories, I further segregate based on 

1. albums (organized by members)
2. various resizings (for different
places on the site

Final structure looks something like

```
/images/members/000/001/1/album1/original
/images/members/000/001/1/album1/50x50
/images/members/000/001/1/album1/75x75
/images/members/000/001/1/album1/400x300

```

The `str_split(str_pad())` in the function probably isn't optimal, but for now it works.
Yes, lots of files in one folder can slow down seeks for files in that folder. At least in the major OSs. In theory it doesn't have to be that way.

Other sites use the date too. Not just user ids or image ids. Just another way to do the same thing.