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.
The way i do it is using folder which contain id numbers,

```
/img/0-100/1
/img/101-200/102

```

This will give you an easy way of looking up your images and the folder will stay quite small.
And there's no extension because i save this in the database.