PHP Chmod directory one level up

Discussion in 'PHP' started by RxDx, Aug 15, 2010.

  1. #1
    Hello,

    I need to chmod a directory that is 1 level up.

    I tried :

    system("chmod -R 755 \"../directory\"");
    PHP:
    but it does not work. Any suggestions?
     
    RxDx, Aug 15, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    chmod("../directory", 0755);
    PHP:
    Give that a go.
     
    danx10, Aug 15, 2010 IP
  3. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    That would not work because PHP didn't create that folder. Just tested it and as always : Operation not permitted.
    When using system chmod it can chmod any folder, no matter who created it.
     
    RxDx, Aug 15, 2010 IP
  4. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #4
    For some reason, this works for me:
    
    <?php
    system("chmod -R 755 ../directory");
    ?>
    
    PHP:
     
    Rainulf, Aug 16, 2010 IP
  5. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    Does not work at all for some reason, even for directory on same level.
     
    RxDx, Aug 17, 2010 IP
  6. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Hmm, any ideas? I would be very grateful is someone could help.
     
    RxDx, Aug 18, 2010 IP
  7. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #7
    If you use chmod from the command line does it work?
     
    exam, Aug 18, 2010 IP
  8. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #8
    exec('chmod 777 ../directory');
    PHP:
    Try that
     
    danx10, Aug 18, 2010 IP
  9. RxDx

    RxDx Guest

    Messages:
    44
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #9
    exam, it worked on the folder in same directory, so server allows to CHMOD.

    danx10, No, does not work.
     
    RxDx, Aug 18, 2010 IP
  10. somyatrans

    somyatrans Peon

    Messages:
    15
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #10
    chmod("../directory", 0755);
     
    somyatrans, Aug 19, 2010 IP
  11. nico_swd

    nico_swd Prominent Member

    Messages:
    4,153
    Likes Received:
    344
    Best Answers:
    18
    Trophy Points:
    375
    #11
    nico_swd, Aug 19, 2010 IP
  12. Rainulf

    Rainulf Active Member

    Messages:
    373
    Likes Received:
    12
    Best Answers:
    0
    Trophy Points:
    85
    #12
    Probably a restriction your host placed on you or security settings on your server because I can totally do anything with system, exec and chmod functions. It's best to ask them.
     
    Rainulf, Aug 19, 2010 IP
  13. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #13
    Quote from the documentation:

     
    danx10, Aug 19, 2010 IP
  14. exam

    exam Peon

    Messages:
    2,434
    Likes Received:
    120
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Try this:

    system("chmod -R 755 " . realpath('./../directory'));
    // or 
    chmod(realpath('./../directory'), 755);
    PHP:
     
    exam, Aug 20, 2010 IP
  15. Dennis M.

    Dennis M. Active Member

    Messages:
    119
    Likes Received:
    7
    Best Answers:
    0
    Trophy Points:
    58
    #15
    How about checking if the directory exists? First and foremost, you must have sufficient privileges on the directory above on which you would like to CHMOD.

    Something like:
    
    if(is_dir("../directory")) // Make sure we exist
        chmod("../directory",0755); // CHMOD should work on *nix _ONLY_ unless you're using some Widnows' emulator for it
    
    PHP:
    If you're looking to do a recursive CHMOD on the directory and its contents, you're going to need to use a loop. Simply opendir(); and readdir(); and chmod appropriately on all files without name "." or ".." That should work if your PHP is properly setup.

    Regards,
    Dennis M.
     
    Dennis M., Aug 21, 2010 IP