/    Sign up×
Community /Pin to ProfileBookmark

allowing file permission changes

i try using chmod() but my permissions are denied. i know what that means, i just don’t know how to change it from the web page without turning it on, but i don’t konw how to do that.

google didn’t help.

to post a comment
PHP

19 Comments(s)

Copy linkTweet thisAlerts:
@chazzyOct 20.2005 — Eek said that all wrong.

It depends on who is running the php process. I'm also assuming that you have the correct paths. So if you have a "php" user that only has access in his root directory - /var/lib/php for example, they will only be able to modify children of that file system.
Copy linkTweet thisAlerts:
@JDM71488authorOct 20.2005 — i have my own domain. im developing an app that the user will upload to their server, so the php page will change all the files it creates to 777 or 755 so they be altered later.
Copy linkTweet thisAlerts:
@chazzyOct 20.2005 — i have my own domain. im developing an app that the user will upload to their server, so the php page will change all the files it creates to 777 or 755 so they be altered later.[/QUOTE]

I'm not sure what either of those statements have to do with your problem, unfortunately.

You have a permissions issue. the PHP process on your server is started by a particular user. In default PHP/MySQL setups, these are both typically owned by users of the respective name. Is this how yours is setup? If so, you need to go back and check that your PHP user has RWX on the particular directory/file system in question.
Copy linkTweet thisAlerts:
@JDM71488authorOct 20.2005 — i run chmod($file, "755") because trying to delete gives me: "Warning: unlink(file name here): Permission denied in..."

thanks for sticking with me
Copy linkTweet thisAlerts:
@chazzyOct 20.2005 — I'm sorry, but can you please verify what I have said:

[i]The PHP user has RWX on the given directory[/i]

Can you give a little more insight as to what you are trying to do? I'm assuming that this script is being called after the file's been uploaded to the server. What kind of system is this? Linux? Windows?
Copy linkTweet thisAlerts:
@JDM71488authorOct 20.2005 — You have a permissions issue. the PHP process on your server is started by a particular user. In default PHP/MySQL setups, these are both typically owned by users of the respective name. Is this how yours is setup? If so, you need to go back and check that your PHP user has RWX on the particular directory/file system in question.[/QUOTE]

what user are you talking about? i am the user. i bought a domain and i login to access my files... i try deleting a file from a php script [unlink()], which i cant, so yes RWX is not set for me. but i dont know how to turn it on so i can rename, delete, and move files via php scripts.

i see no php.ini file in my directory, and i dont even know if that would solve my problem.

help any?
Copy linkTweet thisAlerts:
@chazzyOct 20.2005 — php.ini is not your issue.

Ok.

I understand what the issue is now.

Try this.

All of the files are going to be uploaded to a particular directory? Make sure that that directory itself is chmodded 777. now try it out.

if not...

You're on a hosted environment -- not an environment you setup yourself. The user is the user that owns the process. It doesn't take into account what user is logged in, it's looking at who is running the equivalent of "php.exe" on the system. You need to contact your host at this point and verify with them that you can read, write, delete from inside of a php script.

In Linux and Unix, the concept of user is a little bit more vague than in windows. User's don't necessarily need to exist, physically. A user is a person who owns a process, in most setups the MYSQL instance is owned by the system user "MYSQL" and the PHP instance is owned by the user "PHP" (this does vary). The file systems that processes under the instances can affect are related to what user owns them.
Copy linkTweet thisAlerts:
@JDM71488authorOct 20.2005 — wow. i looked at the permissions (which i should have to begin with, but from the error i figured that it was the problem) and they all say 777. every file, every folder involved, everything.

edit: i tried it again and it worked... ?

thanks for your help, but i still dont know how i can make it not do this if i were to give the source to another person to use. other people shouldn't have to change permissions... i want my code to do that...
Copy linkTweet thisAlerts:
@chazzyOct 20.2005 — say that again, you chmod'd everything again and it worked?
Copy linkTweet thisAlerts:
@JDM71488authorOct 20.2005 — no, i didn't do anything... the whole day i was messing with unlink() trying to delete a sample file it said i didn't have permissions... the permissions were already set to 777, i just didnt know that.

but once i opened them up and saw that they were 777 and clicked ok the script worked.

weird huh?
Copy linkTweet thisAlerts:
@NogDogOct 20.2005 — When a PHP page is run by the webserver, its process is run under its own user ID which is [b]not[/b] the same as your user ID. Typically, this user name is 'nobody' in most installations. A chmod can only be performed by the file owner, regardless of it permissions. Thus, unless the file was either created by your PHP process or you've done a chown (probably via the root user) to change ownership of the file to the PHP user, your PHP pages will not be able to chmod a file.

The PHP chmod() function is mainly there for scripts created to be run via the command line interface (CLI), not via web pages (especially since that could create a serious security problem).
Copy linkTweet thisAlerts:
@chazzyOct 20.2005 — i wouldn't call it weird...

i'm thinking more along the lines of the operation didn't reset completely. by default, most files have 644 permissions.. this will allow anyone to read or execute a file but not write to it, only the owner can write. delete's a write command.

you might get different results for uploaded files via a form vs. files ftp'd to the server. play around with it once you get upload to work.
Copy linkTweet thisAlerts:
@JDM71488authorOct 20.2005 — well i am making a file manager in a way, but i have it to make new files and delete files that are stored in particular folder. in a way its a database, but each entry is its own file. would that be a legit reason for using those functions? i don't see how else i could do it? what kind of security am i going to run into? generic is fine, i can google. indepth is appreciated! ? thanks


----------------------------------------------------------------------

chown to php user upon creation so i can delete or whatever else i have to do later, right?
Copy linkTweet thisAlerts:
@chazzyOct 20.2005 — as i said, play around with it.

i'm pretty sure if you upload it via a webform, it's owned by the PHP user. then you can chmod it.

also, nogdog, there are a lot of scripts that use chmod/unlink and other unix/linux commands. phpBB i know uses it. that's how it writes your configuration file.
Copy linkTweet thisAlerts:
@JDM71488authorOct 20.2005 — what i don't understand is what chown() defaults to.

if i run this script i found on a site:
if( !chown ($file, "user") )
{
echo ("Unable to change file ownership");
}


what is "user"? how can i set me as "user". or is that everyone?
Copy linkTweet thisAlerts:
@chazzyOct 20.2005 — when you upload a file via a client program such as WS_FTP, all files uploaded are "own"'d by the user that uploaded them, you.

however, you don't own the php process. the php process does not have jurisdiction over your files unless you specify it. normally, when you upload via a webform, it's assuming the php user is the owner, and it sets the owner to that user.

as for their name, it depends on how they set it up. some have a generic process starter, some use individuals for each script they want to have running.
Copy linkTweet thisAlerts:
@JDM71488authorOct 20.2005 — so i should just set it to "user" so that anyone using these files on their own domain will automatically have permissions to RMX on the directory?
Copy linkTweet thisAlerts:
@chazzyOct 20.2005 — no no...

you don't understand.

when you upload via a web form, it should automatically make the user php.

if you add in your script to chown to the php user (which you don't know their name..) it won't do anything.
Copy linkTweet thisAlerts:
@JDM71488authorOct 20.2005 — oh! ? i get it. thanks
×

Success!

Help @JDM71488 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...