Re: Setting group sticky bit on directory with chmod()

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On 8/2/07, Ben Ramsey <ramsey@xxxxxxx> wrote:
> I'm trying to set a sticky bit on a directory with chmod(). The same
> octal value works from the command prompt, but it doesn't appear to work
> correctly with the PHP function. Anyone have an idea as to why?
>
> PROMPT (works):
> $> chmod 2775 /path/to/dir
>
> PHP (doesn't work):
> chmod('/path/to/dir', 02775);
>
> We've tested the PHP code on files, and it works, but it doesn't work on
> directories.
>
> Our current umask is 0002. We're using PHP 5.2.2 on Linux ########
> 2.6.9-42.0.10.ELsmp #1 SMP Fri Feb 16 17:17:21 EST 2007 i686 i686 i386
> GNU/Linux.
>
> --
> Ben Ramsey
> http://benramsey.com/
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>

    Ben,

    Drop the preceding 0 from the chmod() function parameters.  The
four-digit octal value is preferred, and the 0 is the first bit to
show that there's no user- or group-specific execution (su-exec'ing,
basically) or "stickiness" to the file/directory.  However,
three-digit values will work.  In either case, five digits will not
work.

    Right:
chmod 0755 file.php
chmod 1777 file.php
chmod('file.php',0755);
chmod('file.php',1777);

    Will almost always work, but isn't entirely correct:
chmod 755 file.php
chmod 644 file.php
chmod('file.php',755);
chmod('file.php',644);

    Will never (or at least, SHOULD never) work:
chmod 00755 file.php
chmod 01777 file.php
chmod('file.php',00755);
chmod('file.php',01777);

    If you are interested in things like this, search the archives for
a post I made a few months back about permissions.  It's a long one,
but in my opinion, a pretty damned good article stub.

    /me pats self on back without regard.

-- 
Daniel P. Brown
[office] (570-) 587-7080 Ext. 272
[mobile] (570-) 766-8107

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux