Writing to a File in PHP on Hosting
As a rule, virtual hostings work through Linux. This OS has a feature related to access permissions to folders. On virtual hosting, it might be the case that the folder you want to write your file to is closed for writing.
For example, let's try
to write a file to the test folder
(this folder should already be created by you):
<?php
file_put_contents('test/file.txt', '123');
?>
If the write is successful, then everything is fine with you. If not, you need to open write access to our folder. One way to do this is via FileZilla.
Let's do it. Open your site via FileZilla and right-click on the folder you want to change permissions for. In the menu that appears, select the File permissions item.
Let's check if there is write permission for the folder owner:
If there is no permission, let's grant it:
Create a folder on your site via FTP. Try to create a file in this folder via PHP.
Check the access permissions to your folder. If necessary, grant write access.