I’m looking for a solution to detect changes in folder(s) using php. The application may run on both platforms(linux and windows). I may use different methods for each platform as long as results are the same.
What I desire is :
- If a file/folder is added to a directory, I want my app to detect this new file and read its attributes (
size,filetimeetc) - If a existing file/folder is saved/contents changed/deleted, I need to detect this file is changed
- It would be better if I can monitor a base folder outside webroot of apache (such as
c:\tmp, ord:\musicon windows or/home/ertuncon linux)
I read something on inotify but I’m not sure it meets my needs.
So if you are checking compared to the last time you checked rather than just being updated as soon as it changes you could do the following.
You could create an MD5 of a directory, storew this MD5 then compare the new MD5 with the old to see if things have changed.
The function below taken from http://php.net/manual/en/function.md5-file.php would do this for you.
This is rather inefficient though, since as you probably know, there is no point checking the entire contents of a directory if the first bit is different.