问题描述
可以直接在PHP或Node上侦听文件夹和文件的更改(按事件),或者我需要使用自己的方法来做到这一点?
It's possible to listen folders and files changes (by events) on PHP or Node directly, or I need make my own method to do it?
示例:我需要收听文件夹/user
.如果我将一些文件添加到该目录中,则PHP或Node会接收到该信息并例如运行PathEvent::fileAdded("/user/user.profile")
.如果我重命名文件夹,它将运行PathEvent::pathRenamed("/user/save1", "/user/save2")
.
Example: I need to listen the folder /user
. If I add some file into this directory the PHP or Node receives the information and run PathEvent::fileAdded("/user/user.profile")
for instance. If I rename a folder it run PathEvent::pathRenamed("/user/save1", "/user/save2")
.
我知道PHP没有像Node这样的事件系统.但是对于PHP,例如,我可以运行一个方法(目前尚不知道),该方法具有自上次检查以来发生的更改.
I know that PHP don't have an event system like Node. But for PHP I can, for instance, run a method (that I don't know currently) that have the changes ocurred since last time checked.
好吧...我只需要一种开始搜索的方式,我不知道搜索的确切含义是什么.如果您可以举一个例子,那就太好了! :P
Well... I need only a way to start searching, I don't know exactly what is the term of this search. If you can show me an example, it'll be great too! :P
推荐答案
Node.js提供了此功能.您可以在此处阅读.
Node.js provides this functionality. You can read bout this here.
简单的例子:
var fs = require('fs');
fs.watch('somedir', function (event, filename) {
console.log(event);
console.log(filename);
});
注意:
这篇关于监听文件夹和文件(更改)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!