Page 1 of 1

permission warning for file_put_contents but works anyway

Posted: Sun Feb 01, 2009 5:38 am
by Matt2012
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?

Re: permission warning for file_put_contents but works anyway

Posted: Sun Feb 01, 2009 3:59 pm
by infolock
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) ?

Re: permission warning for file_put_contents but works anyway

Posted: Sun Feb 01, 2009 5:44 pm
by Matt2012
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

Re: permission warning for file_put_contents but works anyway

Posted: Mon Feb 02, 2009 11:05 am
by pickle
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.

Re: permission warning for file_put_contents but works anyway

Posted: Mon Feb 02, 2009 12:21 pm
by Matt2012
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..

Re: permission warning for file_put_contents but works anyway

Posted: Mon Feb 02, 2009 2:02 pm
by infolock
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

Posted: Thu Feb 12, 2009 3:49 am
by Matt2012
Solved this issue by unlinking the file being written over prior to the file_put_contents,

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);
My host dont allow chmod in php.ini