Hello, I am trying to write an installation module for a script that I wrote to allow the user to install my script without having to do any coding and working on the server...

I wrote this function:

function tbs_chmod($path) {
	global $tbs_install_folder;
	if ( chmod($path,0777) )
		return $path.' successfully chmodded.<br />';
	else
		return $path.' needs to be chmodded 777 (now it is '.fileperms($path).')<br />';
}

echo tbs_chmod($_SERVER['DOCUMENT_ROOT'].'/tbs/userfiles/image');

but all I get is:

Warning: chmod() [function.chmod]: Operation not permitted in /home/eastside/public_html/tbs/install.php on line 10
/home/eastside/public_html/tbs/userfiles/image needs to be chmodded 777 (now it is 16877)

Am I doing something wrong? Why is the operation not permitted? And why is it saying that that folder is set to permissions 16877 even though my FTP software says it is set to 755?

Thanks

    marcnyc wrote:

    And why is it saying that that folder is set to permissions 16877 even though my FTP software says it is set to 755?

    16877 is 040755. Unfortunately, I was not aware that Unix permission modes have a fifth significant octal digit, so I have no idea what the 4 means.

      can I convert that number into 755 somehow?
      also why is the operation not permitted?

        marcnyc wrote:

        can I convert that number into 755 somehow?

        On the other hand, I do know that the file type is displayed with the permissions when doing a long listing... so perhaps the 4 merely refers to the file being a "normal" file, as opposed to say, a directory. If so, it is really telling you the same thing as your FTP client. In fact, now that I check the PHP manual on [man]fileperms/man, it seems like I may be correct. (Oh, and it provides an answer to your question too.)

        marcnyc wrote:

        also why is the operation not permitted?

        Perhaps because the web server user is not the owner of the file and thus is not allowed to chmod it.

          I saw on the manual that there is a function to change owner... is it possible to change the owner to something that would make it permitted?
          If so how do I know what to change it to? is there a way to list the owners of the files?
          If I uploaded the files via FTP is the owner not the web server?

            marcnyc wrote:

            I saw on the manual that there is a function to change owner... is it possible to change the owner to something that would make it permitted?

            The problem is that if the web server user has the permission to change owner, then it would be either the owner or a super user (which is probably a bad idea for a web server user). But if it is a super user, then it can chmod any file, even if it is not the owner.

              is there a way for me to figure out which user is who and can do what? I am not quite clear about this concept...

                ok so since there seems to be no way to achieve this with chmod() I decide to try to a different route:
                my thinking is, if I can chance the permissions of a file or folder with my FTP software, then I should be able to use the ftp functions of PHP to connect to the file and chmod it using ftp_chmod(). Is this correct?
                I am trying and trying but it still doens't work. Can somebody tell me if I am just wasting time or if this can be done?

                  Write a Reply...