write code to file

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

write code to file

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You can chmod() it...
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

You'll need to chown() it first via whatever you used to originally write the file.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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...
There are 10 types of people in this world, those who understand binary and those who don't
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

There are 10 types of people in this world, those who understand binary and those who don't
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post 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.
There are 10 types of people in this world, those who understand binary and those who don't
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post 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?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

That's what sudo is for. ;)
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post 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
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

If it's that terribly important, putting the document outside of the document root should add a layer of security.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Post by VladSun »

feyd wrote:That's what sudo is for. ;)
Are you ROOT === Do you SUDO ;)
There are 10 types of people in this world, those who understand binary and those who don't
Clukey
Forum Commoner
Posts: 60
Joined: Fri Apr 21, 2006 9:05 pm

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

VladSun wrote:Are you ROOT === Do you SUDO ;)
No, it does not.
Post Reply