Is it good to store dynamically created file's paths in database ?
T开发者_高级运维his is in reference with my earlier question how to organize files created dynamically using php?
I edited the question , with one more aspect, that is storing paths in to the DB. Are there any advantages or disadvantages of doing this?
If you have no other way of finding the file, storing its path in the DB is probably OK.
Still, a couple of notes :
- I would generally try to see if I could "guess" the file's path from another field -- for instance, from the primary key
- If it's possible, then, there is no need to store the path in the DB, as it would be some redundant information
- I would, as much as possible, store some relative path, and not an absolute one.
- For instance, I would store
images/my/image-test.png
- But not
/var/www/images/my/image-test.png
- That way, moving the directory with the images to another place, or changing of server, using a new one with another path to the DocumentRoot, would still be OK and not break my application.
- For instance, I would store
精彩评论