How to write to a file on the server in the site folder, in the server folder? not written to the file folder of the site - displays: "the file is not created." This example does not write the file to the site folder. The directory where you need to create and write the file is in the root folder of the site.

$today = date("dmY"); $id_price_list=18; $text="Прайс-лист ".$id_price_list." новый гуид ".$resAr['guid']." старый гуид ".$arDBElement["XML_ID"]."\r\n"; //$file="http://".SITE_SERVER_NAME."/logs_for_price_list/guid_1C_not_export/".$today.".txt"; $file="//logs_for_price_list/guid_1C_not_export/".$today.".txt"; echo $file; $handle = fopen($file, "a");//Открываем для записи в конец. if (!$handle) { echo "Oшибка: файл не создался-".$text; } else { fputs ($handle, $text); fclose($handle); } 

    1 answer 1

    Apparently, the server where the site is located, works under Linux. Therefore, the essentially incorrect path entry //logs_for_price_list/guid_1C_not_export/ points not to the folder in the site root, but to the folder in the root of the server's file system. And, of course, there is no such folder. Not to mention that writing there for web application scripts is prohibited.

    To write a file to the site root, you must first determine the correct path to this root. Usually it is enough to use $_SERVER["DOCUMENT_ROOT"] . Bitrix has a constant storing this path: SITE_DIR

    And then we form the path to the file

      $file = $_SERVER["DOCUMENT_ROOT"] . "/logs_for_price_list/guid_1C_not_export/" . $today . ".txt"; 

    And, of course, the directory must exist, and the script must have rights to write to this directory.