好的,我正在尝试创建一个使用 PHP shell 脚本的电子邮件记录器。我已经设置 CPanel 将电子邮件通过管道发送到我的脚本。我确信这一切都配置正确。但是,我在使用脚本时遇到了问题,从 shell 运行脚本时遇到了任何脚本问题。
这是一个例子。
#!/usr/local/bin/php –q
<?php
/* Read the message from STDIN */
$fd = fopen("php://stdin", "r");
$email = ""; // This will be the variable holding the data.
while (!feof($fd)) {
$email .= fread($fd, 1024);
}
fclose($fd);
/* Saves the data into a file */
$fdw = fopen("mail.txt", "w+");
fwrite($fdw, $email);
fclose($fdw);
/* Script End */
?>
真的很简单,对吧?从 STDIN 读取并写入文件...我认为出了点问题,由于某种原因无法读取 STDIN。托管服务提供商允许,allow_url_open 和 allow_url_include 都打开。
当通过 SSH 执行脚本时,出现以下错误: 无法打开输入文件:âq
所以我又一次认为是脚本告诉我,无法从 STDIN 读取
所以我只尝试了一个简单的脚本。
#!/usr/local/bin/php –q
<?php
echo 'Hello World';
?>
同样的事情: 无法打开输入文件:âq
看来 PHP 程序告诉我它无法打开脚本?该脚本位于 $HOME/mail/forward (CHMOD 755) 中,脚本本身是 CHMOD 755,文件 mail.txt 也是 CHMOD 755 我真的很难过。
最佳答案
我刚刚遇到了这个问题,那是因为我试图从错误的目录运行脚本..doh!它发生在我们最好的人身上。
关于php - PHP shell 脚本 : "Could not open input file" 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4567688/