You need to create a file, write information to it and save it to a specific folder.

At the root of the file is created

$file = "$index.php"; if (!file_exists($file)){ $fp = fopen("$file", "w"); fwrite($fp, $text); fclose($fp); } 

In the folder I need - no

 $file = "/modules/erps/include/scripts/cron/$index.php"; if (!file_exists($file)){ $fp = fopen("/modules/erps/include/scripts/cron/$file", "w"); fwrite($fp, $text); fclose($fp); } 

enter image description here

What am I doing wrong?

    3 answers 3

    Understood. It was not necessary to prescribe the full path when opening and creating, since it is already recorded in the $file variable

    Correct creation:

     $file = "modules/erps/include/scripts/cron/$index.php"; if (!file_exists($file)){ $fp = fopen("$file", "w"); fwrite($fp, $text); fclose($fp); } 

      $ file = "/ modules/erps/include/scripts/cron/$index.php";

      the first slash means the path from the root, but in the modules structure not in the root, but in the zamulevannoy folder

      • sketched folder - this is the root. if you remove the first slash - it does not save anyway - luckydutch

      Try it like this.

      $ file = "/ modules/erps/include/scripts/cron/index.php";

      if (! file_exists ($ file)) {

      $ fp = fopen ("/ modules / erps / include / scripts / cron / index.php", "w");

      fwrite ($ fp, $ text);

      fclose ($ fp); }