PHP 命令不起作用,除非您转到脚本所在的文件夹


PHP command doesn't work unless you go to the folder where the script is

当我运行以下命令时:

php -q /var/www/project/test.php

但是除非我运行以下命令,否则它不起作用:

cd /var/www/project/

你能帮我运行这个命令吗?

完全限定您的mail.txt文件。将您的 php 文件更改为:

<?php $fh=fopen('/var/www/project/mail.txt','w'); fwrite($fh,'Success'); fclose($fh); ?>