$content = "some text here";
$fp = fopen("myText.txt","w");
fwrite($fp,$content);
fclose($fp);
The above code creates a file in the folder where the PHP script is present. However when the script is called by Cpanel Cron then file is created in home directory.
I want file to be created in the same folder where the php script is present even if its run by cron.
How to do that ?
__DIR__
constant to access current script directory orbasename( __FILE__)
if you are running old PHP interpreter – Sotted