CHMOD

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

User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Takuma wrote:can't you use chmod() function?http://uk2.php.net/manual/en/function.chmod.php
Did you not read ANY of the post?
Did you not read ANY of the manual?
I mean, obviously, chmod() won't work. It's been stated over and over.
Jay Eff
Forum Newbie
Posts: 20
Joined: Sat Oct 26, 2002 11:35 am

Post by Jay Eff »

i have tried, but it doesn't work
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

How about this? Just a try

Code: Select all

<?php
chmod($file,0777);
?>
Where $file being a FILE name and not the directory...
And yes I have read the posts thanks... :evil:

You obviously using Linux so how about this?

Code: Select all

<?php
exec("CHMOD 777 /path/to/dir");
?>
It says on what I've found
There are two arguments for chmod: the permissions and the file/directory name. The permission argument for chmod is based on numbers.

1 stands for execute.
2 stands for write.
4 stands for read.

To set more than one permission on a file/directory, you just add up the permissions. For example, 7 means read, write, and execute permissions. Chmod takes the permissions as the first argument in the order user, group, global. Thus, the command chmod 777 hello will change the permissions of the file hello to read, write and execute by user, group, and everyone else.
Note: To change the permissions of a file/directory, you must be the owner of that file/directory. However, root can change permissions on any file/directory.
And I don't think 0 comes into it...
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

First of all, chmod only chmods files, and he's trying to chmod a directory.

We've tried the exec() thing, but obviously again, it's not working.
Its also been tried as 777 AND 0777, so that's not the problem.

Now, this is a stupid question but i forgot to ask, Jay Eff, you are running a Linux server right?
Jay Eff
Forum Newbie
Posts: 20
Joined: Sat Oct 26, 2002 11:35 am

Post by Jay Eff »

yes it is linux
User avatar
Takuma
Forum Regular
Posts: 931
Joined: Sun Aug 04, 2002 10:24 am
Location: UK
Contact:

Post by Takuma »

Read this...

http://www.ahinc.com/linux101/permission.htm


No you can change permission of directory

http://simplythebest.net/info/unix_permissions.html

What's does it say at the top?
rev
Forum Commoner
Posts: 52
Joined: Wed Oct 02, 2002 3:58 pm
Location: Atlanta, GA

Post by rev »

I have not seen anyone mention the following, but it's critical to changing file permissions, opening files, writing files, or doing anything with a given file system in linux. The directory/file that you are attempting to open, which user/group has ownership of the directory and/or file? If the web server user does not have ownership then this might be keeping you from being able to manipulate the directory/file.

If it is a different user from the one running as web server (user nobody by default), and if you have command-line access and think it smart to do so, 'chown -R webServerUser.webServerGroup /path/to/dir' where, by default, webServerUser would be 'nobody' and webServerGroup would be 'nobody'.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

php-chmod-function works and it will change directory permissions as well, just like the shell-command does. Both use the same kernel-call.

when creating a directory from within a php-script note that mkdir() can take a second parameter for the permission settings
also note umask()

fileowner() will tell you the owner id. Your id should be stored in the enviroment variable UID or EUID (effectiv user id)

Code: Select all

echo 'uid:', getenv('UID'), ' euid :', getenv ('EUID');
or more likely to work

Code: Select all

system('echo $UID');
system('echo $EUID');
User avatar
hob_goblin
Forum Regular
Posts: 978
Joined: Sun Apr 28, 2002 9:53 pm
Contact:

Post by hob_goblin »

Okay sorry for saying it 'can only' chmod files, but, from my experience alot of people have been having problems with directories. Most of these people got around it with using exec() somehow. The problem here is probably that php isn't finding the directory.
Post Reply