PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
arpowers wrote:Hey guys,
What is the best method of managing photos with a php/mysql application??
I've done a little looking around and it seems like some use a database and other use directories...
can anybody straighten me out?
Thanks!
Andrew[/s]
You don't need straightening out (as far as I know), it's just that there is no single or simple answer to your question. There are two options: store images as blobs in a table, and store path/filename pointers to wherever the images are stored as files.
If you have very large numbers of very large images, storing them in a table might cause a performance problem. If you store them as files, problems can arise from the files or their paths being changed or the files can be deleted without updating the table. So your choice will depend on the relative importance of such factors. That's why some use one option and others use another option.
I think more often than not, you're going to hear the same thing from experienced developers - keep the files in the filesystem. The performance gain is huge. I had one photo repository system that started out using the database as the storage medium. It had about 900 100x100 images (not very large). The second version used the filesystem & was about 2-3x faster than the database version. Development was marginally more complex, but very worth it.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
@mordred - not really. At least from what I've noticed. On a freebsd platform I easily had over 100,000 images. Performance was no problem. The problem came when opening the folder and reading the contents. Plus, by default, most ftp clients only like to read 2000 file entries. I backed up my site on a windows drive, and php had no problems accessing the images directly, but opening the folder was hellacious. I don't know how this would scale if the images were into the million+ count, but I wouldn't see a reason for problems.
However, it's suggested that you organize your image file system as much as possible.
Or use the date instead of user.. something that's easily navigable and relatively easy to determine what's inside the folder.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
Windows generally (at least in older, than Vista, versions) had performance drops at multiples of 500 items per folder or something. Systems which are accessed heavily should be split apart too, to help performance.
y'all know I like to store data as the md5 of it's contents. If I have a system where there will be more than a few thousand files I store in alphabetical directories based on he first so many characters, like so: