运行 PHP 在 Putty 中给出 'Could not open input file'
Running PHP in Putty gives 'Could not open input file'
我在 Putty 命令行中写
/usr/bin/php /var/www/html/folder/file.php
也试试
php /var/www/html/folder/file.php
两者都给'Could not open input file'
文件权限为777,操作系统为UNIX
PHP 脚本:
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: CRON';
mail('admin@website.com','CRON',"<b>THIS IS SIMULATION TEST</b>",$headers);
?>
使用相对路径。即,如果您从那里 cd 进入 /var/www/html/folder 和 运行。
当 Windows 换行符结尾 (\r\n) 而不是 PHP 中的 Unix 样式 (\n) 时,有时会发生这种情况或 cron 文件。
修复:将行结尾转换为 Unix 样式
dos2unix /var/www/html/folder/file.php
或
sed -i 's/\r//' /var/www/html/folder/file.php
或
使用Notepad++等编辑器转换EOL:
- 在记事本++中打开文件
- 双击右下角的"Dos/Windows"
- 改为"UNIX/OSX format"
- 保存、上传并测试
.
请记住,对 PHP 文件和包含您的 cron 命令的文件都执行此操作。
我在 Putty 命令行中写
/usr/bin/php /var/www/html/folder/file.php
也试试
php /var/www/html/folder/file.php
两者都给'Could not open input file'
文件权限为777,操作系统为UNIX
PHP 脚本:
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'From: CRON';
mail('admin@website.com','CRON',"<b>THIS IS SIMULATION TEST</b>",$headers);
?>
使用相对路径。即,如果您从那里 cd 进入 /var/www/html/folder 和 运行。
当 Windows 换行符结尾 (\r\n) 而不是 PHP 中的 Unix 样式 (\n) 时,有时会发生这种情况或 cron 文件。
修复:将行结尾转换为 Unix 样式
dos2unix /var/www/html/folder/file.php
或
sed -i 's/\r//' /var/www/html/folder/file.php
或
使用Notepad++等编辑器转换EOL:
- 在记事本++中打开文件
- 双击右下角的"Dos/Windows"
- 改为"UNIX/OSX format"
- 保存、上传并测试
.
请记住,对 PHP 文件和包含您的 cron 命令的文件都执行此操作。