Well the first thing i would do is identify what exactly defines an image...:
image {
name
type
size
...etc?...
}
then determine how you want to search and retrieve these images... (i.e. pull them up by name, or sort them by type... or get only images > 40k). once you have that worked out you can give each image a unique id || name... then setup a directory structue... in my demo i would like to sort by type... then size... then name... so i would setup my dir structure like so:
/images
/images/gif
/images/gif/0k-99k
/images/gif/0k-99k/a
/images/gif/0k-99k/a/aa
/images/gif/0k-99k/a/ab
/images/gif/0k-99k/a/ac
/images/gif/0k-99k/a/{etc}
/images/gif/0k-99k/b/
/images/gif/0k-99k/b/ba
/images/gif/0k-99k/b/bc
/images/gif/0k-99k/b/{etc}
/images/gif/100k-199k/{etc}
/images/gif/200k-299k/{etc}
/images/jpeg/{etc}
/images/png/{etc}
/images/{etc}
so if my username where aardvark... and i had an image of size 345k and it was a jpeg the path to my image would be
/images/jpeg/300k-399k/a/aa/aardvark_$uniqueidentifier.jpeg
then i would take that path.. store it into a database along with the other fields that determine what exaclty the image is defined as... so now what i have is all the information that makes up an image is stored into a row on my database and given an unique id and the the path to the actuall file... and if need be i can still browse my dir structure intellegently and retrive/search images without being lost... and inorder to pull the image off the disk using php all i need to pass to my image retiving funciton is its uniqe identifier... or if you want to get fancy any number of feilds that make up an image and have the function return an array of files to be pulled up according to your search paramaters... also the code to build this dir tree could allow for it to expand on itself... say for instance you have 100,000 images and all of them are in the dir 100k-199k and you get some dude that wants an image 523k well the code would create the neccesary dirs inorder for him to store his image... thus the scaling would be seemless.
$0.02
-Jon