I wrote a function for my sites that converts user IDs into a hierarchy of two-level subdirectory, which limits the 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; }
(In fact, I am adding a third level with a raw user ID to process the 1,000,000 survey.
/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
In these subdirectories, I further separate based on
- albums (organized by members)
- various changes (for different places on the site
The final structure looks something like this:
/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()) function in the function is probably not optimal, but at the moment it works.
source share