首页 > 解决方案 > PHP __DIR__ 在本地工作但不在生产环境中

问题描述

我在 Wordpress 插件中有一个脚本,我正在尝试使用fwrite().

我的代码是这样的:

 $log_url =  __DIR__ . '/logs/update-email-publish-tasks/' . date("n.j.Y") . '.txt';
    $logfile = fopen($log_url, "w"); 
    fwrite($logfile, 'Starting tasks at ' . date("H.i.s") . "\n");

//A bunch of code that logs stuff;

    fwrite($logfile, "\n" . 'Finished at !' . date("H.i.s") . "\n");
    fclose($logfile);

这在本地运行良好,但不适用于生产。我想知道我是否需要使用其他东西__DIR__?我也试过WP_CONTENT_DIR了,没有用。

FWIW 我在万神殿主持制作。

标签: phpwordpressfwritewordpress-plugin-creationpantheon

解决方案


推荐阅读