PHP在与脚本相同的目录中创建文件

Gre*_*hap 5 php cron cpanel

$content = "some text here"; 
$fp = fopen("myText.txt","w"); 
fwrite($fp,$content); 
fclose($fp);
Run Code Online (Sandbox Code Playgroud)

上面的代码在存在 PHP 脚本的文件夹中创建了一个文件。但是,当 Cpanel Cron 调用脚本时,会在主目录中创建文件。

我希望在存在 php 脚本的同一文件夹中创建文件,即使它是由 cron 运行的。

怎么做 ?

Tek*_*ekk 3

尝试使用__DIR__ . "/myText.txt"作为文件名。
http://php.net/manual/en/language.constants.predefined.php