PHP 脚本发送电子邮件列出目录/子目录中发生的文件更改
我有一个目录,其中包含许多子目录,用户可以通过 FTP 将文件添加到其中。我正在尝试开发一个 php 脚本(我将作为 cron 作业运行),该脚本将检查目录及其子目录中的文件、文件大小或修改日期的任何更改。我进行了长时间的艰苦搜索,到目前为止只找到了一个有效的脚本,我尝试修改该脚本 - 原始位置 此处 - 但它似乎只发送第一封电子邮件通知显示目录中列出的内容。它还创建了目录和子目录内容的文本文件,但是当脚本第二次运行时,它似乎崩溃了,我收到了一封没有内容的电子邮件。
有人知道在 php 中执行此操作的简单方法吗?我发现的脚本非常复杂,我尝试了几个小时来调试它但没有成功。
提前致谢!
I have a directory with a number of subdirectories that users add files to via FTP. I'm trying to develop a php script (which I will run as a cron job) that will check the directory and its subdirectories for any changes in the files, file sizes or dates modified. I've searched long and hard and have so far only found one script that works, which I've tried to modify - original located here - however it only seems to send the first email notification showing me what is listed in the directories. It also creates a text file of the directory and subdirectory contents, but when the script runs a second time it seems to fall over, and I get an email with no contents.
Anyone out there know a simple way of doing this in php? The script I found is pretty complex and I've tried for hours to debug it with no success.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
给你:
我假设你知道如何发送电子邮件。另外,请记住,出于显而易见的原因,
$log
文件应保存在您想要监控的$path
之外。第二次阅读你的问题后,我注意到你提到你想检查文件是否发生变化,我只是检查修改的大小和日期,如果你真的想要检查文件内容是否不同我建议您使用文件的哈希值,因此:变成这样:
但请记住,这会更加昂贵,因为哈希函数必须打开并读取 1-5 MB CSV 文件的所有内容。Here you go:
I am assuming you know how to send an e-mail. Also, please keep in mind that the
$log
file should be kept outside the$path
you want to monitor, for obvious reasons of course.After reading your question a second time, I noticed that you mentioned you want to check if the files change, I'm only doing this check with the size and date of modification, if you really want to check if the file contents are different I suggest you use a hash of the file, so this:Becomes this:
But bare in mind that this will be much more expensive since the hash functions have to open and read all the contents of your 1-5 MB CSV files.我非常喜欢 sfFinder,因此我编写了自己的改编版本:
http://www.symfony -project.org/cookbook/1_0/en/finder
https://github.com/homer6/altumo/blob/master/source/php/Utils/Finder.php
使用简单,效果良好。
但是,为了供您使用,根据文件的大小,我将所有内容都放在 git 存储库中。那么就很容易追踪了。
华泰
I like sfFinder so much that I wrote my own adaption:
http://www.symfony-project.org/cookbook/1_0/en/finder
https://github.com/homer6/altumo/blob/master/source/php/Utils/Finder.php
Simple to use, works well.
However, for your use, depending on the size of the files, I'd put everything in a git repository. It's easy to track then.
HTH