Page 1 of 2
write code to file
Posted: Mon Aug 27, 2007 7:02 pm
by Clukey
I am looking for a way to write code to a file, and I have found the fwrite method but to use that I have to change the file permissions to 666, is there any other method that lets me keep the permissions the same, in this case 644.
Thanks
Posted: Mon Aug 27, 2007 7:11 pm
by feyd
Posted: Mon Aug 27, 2007 7:20 pm
by Clukey
but the reason I can't use fwrite is because for some reason the server sees the script's owner as being different than the owner of the file I am trying to write to so I have to change the permissions to let the "world" edit it, and for the same reason chmod() won't work
Posted: Mon Aug 27, 2007 7:33 pm
by feyd
You'll need to chown() it first via whatever you used to originally write the file.
Posted: Mon Aug 27, 2007 7:45 pm
by VladSun
feyd wrote:You'll need to chown() it first via whatever you used to originally write the file.
There is no way to do it.
You must be ROOT if you are able to...
Posted: Mon Aug 27, 2007 7:54 pm
by feyd
VladSun wrote:No way! Are you ROOT?
Me? Rarely. Never via Apache.
If chown is not available, depending on how the files were placed, one may need to upload (or originally write them) via PHP. This way they will share PHP's user.
Posted: Mon Aug 27, 2007 7:57 pm
by VladSun
Posted: Mon Aug 27, 2007 8:19 pm
by VladSun
feyd wrote:VladSun wrote:No way! Are you ROOT?
Me? Rarely. Never via Apache.
I meant, any user (except root) shouldn't be able to chown files. Otherwise, it would be a critical security hole.
Posted: Mon Aug 27, 2007 8:32 pm
by Clukey
So, if I am understanding you right, since I am on a shared server it isn't possible to edit a file without changing the permissions of the file I am trying to edit. Is that right or did I miss something cause that seems like something that should be possible?
Posted: Mon Aug 27, 2007 8:38 pm
by feyd
That's what sudo is for.

Posted: Mon Aug 27, 2007 8:56 pm
by Clukey
I've never heard of that, but if you mean Sudo as in
http://www.gratisoft.us/sudo/, I don't think will work because I'm not the system administrator, I use a hosting service so I don't think I can set that up
Posted: Mon Aug 27, 2007 8:57 pm
by s.dot
If it's that terribly important, putting the document outside of the document root should add a layer of security.
Posted: Mon Aug 27, 2007 9:07 pm
by VladSun
feyd wrote:That's what sudo is for.

Are you ROOT === Do you SUDO

Posted: Mon Aug 27, 2007 9:12 pm
by Clukey
Ok, well I didn't think it would be such a big deal, but since I'm not ROOT I guess I'll just change the permissions.
Thanks for the help
Posted: Mon Aug 27, 2007 9:17 pm
by feyd
VladSun wrote:Are you ROOT === Do you SUDO

No, it does not.