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.
This depends mainly on the filesystem. For a modern filesystem like NTFS or ext3, keeping huge numbers of files in the same directory is not a problem, but some older filesystems could not handle it.

However, it may still be a good idea to partition the files into subdirectories according to some scheme, just to keep them manageable with various tools (which may have their own issues with humongous directories) such as backup. BTW, opening a directory in Windows explorer counts as such a case.