dongsheng66783619 2014-03-22 21:35
浏览 61


I feel like I'm missing something here. php is set up in my system variable PATH. I'm trying to execute a php script from the Window command line, here is my script:

$file = "test_log.txt";
$content = date("Y-m-d H:i:s") . " - Action logged. 
file_put_contents($file, $content, FILE_APPEND);

echo "That worked. I think.";

When called from my browser it works perfectly. A log file is appended with the latest action. However when called from the command line I get the echo, but nothing else happens, no appendment of the log file. See below:

enter image description here

Any ideas?

  • 写回答

1条回答 默认 最新

  • dongliao3450 2014-03-22 21:40

    This should do it:

    file_put_contents(__DIR__.'/'.$file, $content, FILE_APPEND);

    Reason: Your webserver has a different $_SERVER['DOCUMENT_ROOT'] (and current work directory) than the Command Line Interpreter.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?



    • ¥20 java的代码出问题了
    • ¥15 yolov8 如何调cfg参数
    • ¥15 这个四人抢答器代码哪儿有问题?仿真程序怎么写?
    • ¥15 burpsuite密码爆破
    • ¥15 关于#ubuntu#的问题,如何解决?(相关搜索:移动硬盘)
    • ¥15 scikit安装之后import不了
    • ¥15 Ros2编译一个使用opencv的c++节点的时候,报了这个错误,请问怎么解决啊
    • ¥15 人脸识别相关算法 YOLO,AI等
    • ¥15 spark问题方便加V17675797079
    • ¥15 Python代码不打印的原因