views:

727

answers:

4

When i use chmod() function to change permission on run time,it give me below message .

Warning: chmod() [function.chmod]: Operation not permitted in /home/loud/public_html/readalbum.php

How i can remove this error and make working of chmod function

+1  A: 

In order to perform chmod, you need to be owner of the file you are trying to modify, or the root user.

Martin v. Löwis
or root of course
Joel
@Joel: right, added.
Martin v. Löwis
+1  A: 
$ sudo chmod ...

You need to either be the owner of the file or be the superuser, i.e., user root. If you own the directory but not the file, you can copy the file, rm the original, then mv it back, and then you will be able to chown it.

The easy way to temporarily be root is to run the command via sudo. ($ man 8 sudo)

DigitalRoss
http://xkcd.com/149/
Greg Hewgill
ROTFL..........
DigitalRoss
I didn't see before the edit, but why the down votes? Looks reasonable now...
atk
I don't know why either, it seemed then and seems now to be the right answer. Before the edits it simply said "$ sudo chmod ...". Remember that lots of downvoting on SO is done for selfish, vindictive, or tactical reasons and has nothing to do with the quality of the answer. I've got lots of rep points, so I don't really care. Someone probably rationalized that I should have explained the unix protection model, but their real reason was likely to be one of those other ones I named..
DigitalRoss
Indeed, the edited answer helped me out a lot, since I completely forgot about copypasta hijacking.
John
+1  A: 

You, or most likely your sysadmin, will need to login as root and run the chown command: http://www.computerhope.com/unix/uchown.htm

Through this command you will become the owner of the file.

Or, you can be a member of a group that owns this file and then you can use chmod.

But, talk with your sysadmin.

James Black
It seems more likely that the OP doesn't *have* a 'sysadmin'.
pavium
Then he will need to login as root, but that is why I gave the link for chown, as talking through group membership would be a bit more work.
James Black
A: 

This is a tricky question.

There a set of problems about file permissions. If you can this at the command line

$ sudo chown myaccount /path/to/file

then you have a standard permissions problem. Make sure you own the file and have permission to modify the directory.

If you cannnot, then you probably have mounted a FAT-32 filesystem. If you ls -l on the file, and you find it is owned by root and a member of the "plugdev" group, then you are certain its the issue. FAT-32 permissions are set at the time of mounting, using the line of /etc/fstab file. You can set the uid/gid of all the files like this:

UUID=C14C-CE25  /big            vfat    utf8,umask=007,uid=1000,gid=1000 0       1

Also, note that the FAT-32 won't take symbolic links.

Wrote the whole thing up at http://www.charlesmerriam.com/blog/2009/12/operation-not-permitted-and-the-fat-32-system/

Charles Merriam