I want to watch a folder from root of FTP. Automatically will be uploaded in the root some files. I need to know when this new file is uploaded and what I have to do is to get the name of the file and to add the name into the database with the file created.
I saw the people recommends to use inotify (Linux). But I can't understand if the code will be write in bash or in a simple php file..If can someone can help me with an example and full explanation
Here an example found on the internet
#!/usr/local/bin/php
<?php
// directory to watch
$dirWatch = 'watch_dir';
// Open an inotify instance
$inoInst = inotify_init();
// this is needed so inotify_read while operate in non blocking mode
stream_set_blocking($inoInst, 0);
// watch if a file is created or deleted in our directory to watch
$watch_id = inotify_add_watch($inoInst, $dirWatch, IN_CREATE | IN_DELETE);
// not the best way but sufficient for this example :-)
while(true){
// read events (
// which is non blocking because of our use of stream_set_blocking
$events = inotify_read($inoInst);
// output data
print_r($events);
}
// stop watching our directory
inotify_rm_watch($inoInst, $watch_id);
// close our inotify instance
fclose($inoInst);
?>