Changing directory permissions?

Discussion in 'PHP' started by brendgard, Feb 15, 2010.

  1. #1
    I have been looking for what I need to see if it is already answered, but the only things I'm seeing is a link back to the php.net site to a page that makes no sense to me. Forgive me please, I don't claim to be a professional coder so a lot of it does not seem to percolate through my head lol.

    lets say I have a directory

    /home/account/public_html/myfolder/

    which is set to 755, but I want to use a PHP script to set it to 0777. How do I do that in simple terms?

    Thanks.
     
    brendgard, Feb 15, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    <?php
    $dir = "/home/account/public_html/myfolder/";
    if(is_dir($dir) && chmod($dir, 0777)){
    echo "Done!";
    }
    ?>
    PHP:
     
    danx10, Feb 15, 2010 IP
  3. skywebsol

    skywebsol Well-Known Member

    Messages:
    161
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    103
    #3
    chmod("/somedir/somefile", 777);
     
    skywebsol, Feb 15, 2010 IP
  4. SmallPotatoes

    SmallPotatoes Peon

    Messages:
    1,321
    Likes Received:
    41
    Best Answers:
    0
    Trophy Points:
    0
    #4
    chmod('/home/account/public_html/myfolder/', 0777);
    PHP:
    Note that in most typical cases, this will only work if /myfolder/ was created by PHP in the first place. That's because chmod won't work unless it's being called by the owner of the file or folder in question. Normally the web server user is different from the user account used to upload files via FTP/SCP. Your mileage may vary.
     
    SmallPotatoes, Feb 15, 2010 IP
  5. brendgard

    brendgard Active Member

    Messages:
    590
    Likes Received:
    9
    Best Answers:
    0
    Trophy Points:
    58
    #5
    Mmmmmmm ok. But what I was reading lead me to believe that the PHP chmod command only worked on files, not directories. I give it a try though. Guess I was even more confused than I thought. Thanks!
     
    brendgard, Feb 15, 2010 IP