fopen function is not working in php.
I wrote the following code in my php file.
$fh = fopen("/home/sugumar/Public_html/sugumar/public_html/123","a+");
fwrite($fh,"hello");
I ran this code from command line: php file_name.php its working fine.
But If I run this code from browser it shows the following error.
Warning: fopen(Logs/add_employee.logs)
[function.fopen]: failed to open
stream: Permission denied in
/home/sugumar/Public_html/sugumar/public_html/HRMS/HRMS_add_emp_DB.php
on line 111Warning: fwrite(): supplied argument is
not a valid stream resource in
/home/sugumar/Public_html/sugumar/public_html/HRMS/HRMS_add_emp_DB.php
on line 113
how to solve this problem?
Thanks in advance.
I don’t think it’s a good idea at all to chmod your public HTML folder to 777. Besides the error message states that it is not the public_html folder that has permission problems, but the Logs folder… specifically this particular file in the Logs folder does not have “write” access: add_employee.logs
To change permissions, just find the location of the Logs folder, then if you have access to SSH, cd to the Logs folder on the server and enter:
This will change the permissions of the add_employee.logs to read + write, so your PHP will be able to write to the file.
If you don’t have SSH, try using your FTP client to connect to the server. Then navigate to the Logs folder on your server (depends on whether your hosting provider allows FTP access to this folder). Depending on the FTP client you have, you should be able to right-click on a file/folder and change permissions for the selected file/folder.
If you can’t access the Logs folder with FTP, your hosting provider should offer a CPanel website for you to login to. From the CPanel, you should have access to some kind of file manager, where you can access the Logs folder and can change the file’s permissions from there. Can’t give you instructions here as I have no idea which CPanel software your hosting provider uses and they’re all very different.