This actually depends on a number of things, but the short answer is that 4000 files should be fine, for the most part.
If your webserver is running linux, you have two main filesystems - ext3 and reiserfs. From Wikipedia:
Compared to ext2 and ext3 in version 2.4 of the Linux kernel, when dealing with files under 4k and with tail packing enabled, ReiserFS is often faster by a factor of 10–15. This is of great benefit in Usenet news spools, HTTP caches, mail delivery systems and other applications where performance with small files is critical.
I'm not sure how large your files are, but if they are small thumbnails, this filesystem might help.
But like I said above, you should be fine with 4000 files per directory.
Also, one thing to note is that you can always just give it a try, and if you notice performance issues, make sure you have an alternate plan set up. You might just have to test a bit to see what works best for your application.
Jay Sudowski // Handy Networks LLC // Co-Founder & CTO AS30475 - Level(3), HE, Telia, XO and Cogent. Noction optimized network. Offering Dedicated Server and Colocation Hosting from our SSAE 16 SOC 2, Type 2 Certified Data Center. Current specials here. Check them out.