Im using file_put_contents and both the file its in and the folder its posting the file to have correct permissions the operation is successful
(the new file is put in the folder) but I get this error message.
The file and folder are in root the script is getting a database backup using cpanel url. The script is run by cron.
<b>Warning</b>: file_put_contents(/../../) [<a href='function.file-put-contents'>function.file-put-contents</a>]: failed to open stream: Permission denied in <b>/../../../</b> on line <b>21</b><br />
So why the error?
permission warning for file_put_contents but works anyway
Moderator: General Moderators
Re: permission warning for file_put_contents but works anyway
sounds to me like you're doing this to multiple files (or are trying to read a different file).
This error can come up with one of 5 reasons:
1) Cannot create file
2) Cannot read file
3) Cannot execute file
4) Cannot write to file
5) Cannot delete file
What are the permissions set to the file(s) ?
This error can come up with one of 5 reasons:
1) Cannot create file
2) Cannot read file
3) Cannot execute file
4) Cannot write to file
5) Cannot delete file
What are the permissions set to the file(s) ?
Re: permission warning for file_put_contents but works anyway
permissions are 777 and the new files are being created but still getting the error message
im basically cycling through all my databases and making a backup to root
im basically cycling through all my databases and making a backup to root
Re: permission warning for file_put_contents but works anyway
I'm sure you can't get a "no permissions" error on an operation, and have it also work. I'm with ~infolock - you're likely doing this multiple times & the failure is happening on a different file.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Re: permission warning for file_put_contents but works anyway
I am doing it multiple times
im also getting an error for each occurrence
and each occurence is working!
strange I know my hosts tell me I can ignore the error so I guess im leaving it but it dosent feel quite right.
I think the issue maybe due to certain restrictions my hosts have put on root anyway ho hum..
im also getting an error for each occurrence
and each occurence is working!
strange I know my hosts tell me I can ignore the error so I guess im leaving it but it dosent feel quite right.
I think the issue maybe due to certain restrictions my hosts have put on root anyway ho hum..
Re: permission warning for file_put_contents but works anyway
in that case, check to make sure group/owner privs are right (not only on the files, but the directory where the files live as well)
Re: permission warning for file_put_contents but works anyway
Solved this issue by unlinking the file being written over prior to the file_put_contents,
like this...
My host dont allow chmod in php.ini
like this...
Code: Select all
$path_week = $home."/weekly/database".date('D').".sql.gz";
if (file_exists($path_week)) unlink($path_week);
$handles['week'] = file_put_contents($path_week,$file);