views:

58

answers:

4

I have a file in my project folder.How i can i give file write permission using php.I used this code

chmod($file,0777);

But it giving an error

Warning: chmod() [function.chmod]: Operation not permitted 

The file is created by another user.Is their any way to do this .Thanks in advance

+5  A: 

This happens because PHP does not have rights to do the change. The user under which PHP runs is usually the web server's user and different from the user you use to add files.

You generally only do chmod on files created with PHP. To be able to do this on other files you need to change the owner (chown).

Alin Purcaru
+5  A: 

The current user is the user under which PHP runs. It is probably not the same user you use for normal shell or FTP access. The mode can be changed only by user who owns the file on most systems.

From http://php.net/manual/en/function.chmod.php

Shoban
+3  A: 

Well - you just can't if it says you are not permitted to. Point is - the file belongs to some user and group, most likely root:root - and you are just a user on the server. If root's the owner of that file, you can't change the permissions at all.

Notes:

$file must be a filename. If you put the handle there, the file (most likely) doesn't exists, but still.

Check if the filename is not beginning with / or something. Try different variations.

Aurel300
A: 

you can install php via SUEXEC or SUPHP instead of mod_php which allows to change the user as which php is executed, still this dosnt solve anything if the owner is set wrong

w13531