There are a lot of questions on SO about storing images with MySQL (or any other RDBMS). Some examples:
- Storing Images in DB - Yea or Nay?
- Can I store images in MySQL
- How can I store and retrieve images from a MySQL database using PHP?
Nearly all answers recommend to store images as files and only have the filesystem path in the database itself, for various reasons. But the problem with this solution is that the database no longer can enforce data integrity for the images. In one answer though, there's a hint that data integrity could be achieved even when the images are stored as files.
One solution I could imagine is using something like inotify
to watch the directory with the image files and call some stored procedure to react to the changes inotify
reported. But that isn't a solution where the database itself would guarantee integrity.
Is there any other way to synchronize and enforce integrity between file paths stored in MySQL and the files in the filesystem?