【发布时间】:2011-02-11 12:47:30
【问题描述】:
您好,
我正在使用 iwatch 观看一个后缀目录。
iwatch /home/vmail/eamorr/photos/new/
发送新邮件时,iwatch 会输出如下一行:
[11/Feb/2011 12:23:43] IN_CREATE /home/vmail/eamorr/photos/new//1297427022.Vca01I1e396M000383.eamorr
如何将其重定向到 PHP 程序进行处理?
这是我尝试过的:
iwatch /home/vmail/eamorr/photos/new/ | php /home/hynese/sites/eamorr/emailPhotoHandler/handlePhotos.php
这里是 handlePhotos.php 文件:
<?php
$data = file_get_contents("php://stdin");
$myFile = "testFile.txt";
$fh = fopen($myFile, 'w') or die("can't open file");
$stringData = $data;
fwrite($fh, $stringData);
fclose($fh);
?>
它应该创建一个文件“testFile.txt”并将“[11/Feb/2011 12:23:43] IN_CREATE /home/vmail/eamorr/photos/new//1297427022.Vca01I1e396M000383.eamorr”放入其中。 ..但我得到的只是什么-文件甚至没有创建...
我认为这与 PHP 中的管道和标准输入有关。
有人有什么想法吗?
非常感谢,
【问题讨论】:
-
iwatch输出未流式传输到管道。 -
iWatch 接受
-c开关以对事件执行命令。试过了吗? -
好了,我可以执行命令了,但是如何获取被修改的文件名呢?
-
print_r($_SESSION) 并且其中一个变量将包含您要查找的内容。
-
我已经尝试过以下命令:
iwatch -v /home/vmail/eamorr/photos/new/ -c "echo '%f' > hi.txt ",但从未创建 hi.txt!