How many images are in your uploaded folder?
- If you have thousands of them, consider making your folders smaller.
- For example, the terminfo system uses /usr/share/lib/terminfo/a/ subdirectory to hold entries that begin with 'a'.
- The CPAN system for Perl uses authors/id/A/AB/ABRAHAM to divide things up.
The point is that the system probably does a linear search through the directory to find the files, and not all of them can be at the beginning. By splitting them up into smaller sub-directories, you greatly improve the lookup time - and hence the speed of any and all file open functions.
There was a paper or discussion about this - I think it was in Eric Raymond's 'The Art of Unix Programming', but it referenced some papers where the measurements were made - and it can give valuable speedups at minimal programming cost.
If done properly, you can write a simple function to generate the file name from the image storage base directory and the image file name.