#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    364
    Rep Power
    12

    CHMOD folder and all subfolders/files


    This script works to chmod a single specified folder. But I would like to set up this script to CHMOD all subfolders/files.
    PHP Code:
    <?php

    /* Connect to FTP server */
    $conn ftp_connect('ftp.site.nl');
    if (!
    $conn) die('Unable to connect to ftp.site.nl');

    /* Login as "user" with password "pass" */
    if (!ftp_login($conn'user''pswd')) die('Error logging into ftp.site.nl');

    /* Issue: "SITE CHMOD 0777 /home/user/privatefile" command to ftp server */
    if (ftp_site($conn'CHMOD 0777 public_html/access/chmodtest')) {
       echo 
    "Command executed successfully.";
    } else {
       die(
    'Command failed.');
    }
    ?>
    I'v tried ftp_site($conn, 'CHMOD -R 0777 public_html/access/chmodtest') and it dosent work. Appreciate any help. Thanks
  2. #2
  3. No Profile Picture
    Redpill
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2005
    Posts
    1,660
    Rep Power
    152
    Try writing a recursive function to do the job. I'm a bit lazy to work out the details, but here's a rough guide:

    PHP Code:
    function chmod_recursive($dir$chmod)
    {
        for 
    each file in $dir as $file
            
    if $file is directory
                chmod_recursive
    ($file$chmod)
            else if 
    $file is regular file
                regular_chmod
    ($file$chmod)
        
    endloop

    Comments on this post

    • SKDevelopment agrees
    • PHPme agrees
    Code:
    #include <stdio.h>
    int main(int o,char**O){return o>-1?o-2||!main(-1,1+O)?!!fprintf(stderr,"%s [0-"
    "9]{81}\n",*O):main(-83,++O):o>-83?(*O)[-1-o]?81==(o=-o-1)||o[*O]<'0'||'9'<o[*O]
    ?0:main(-2-o,O):o==-82:o>-164?(*O)[-83-o]<'1'?main(o-82,O):main(--o,O):o+164?o>-
    246?(*O)[-165-o]<'1'?main(o-82,O):main(--o,O):o+246?o>-328?(*O)[o=-o-247]<='8'?(
    main(-328-o,(++o[*O],O)),main(-247-o,O)):!(o[*O]='0'):(o=-o-328)<729?(o%9/3*3-o%
    27+o/243*9+o/81%3&&(*O)[o%81]==(*O)[o%81-o%27+o%9/3*3+o/243*9+o/81%3])||(o%81-o%
    9-o/81*9&&(*O)[o%81]==(*O)[o%9+o/81*9])||(o/81-o%9&&(*O)[o%81]==(*O)[o%81-o%9+o/
    81])?0:main(-409-o,O):main(-165-o%81,O):!puts(*O):0                           ;}
  4. #3
  5. No Profile Picture
    Contributing User
    Devshed Beginner (1000 - 1499 posts)

    Join Date
    Jan 2004
    Posts
    1,014
    Rep Power
    788
    CHMOD 0777 is a bit drastic don't you think? This gives access to everybody and their grandma to delete, modify and upload files and directories...
  6. #4
  7. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    364
    Rep Power
    12
    Originally Posted by jafet
    Try writing a recursive function to do the job. I'm a bit lazy to work out the details, but here's a rough guide:

    PHP Code:
    function chmod_recursive($dir$chmod)
    {
        for 
    each file in $dir as $file
            
    if $file is directory
                chmod_recursive
    ($file$chmod)
            else if 
    $file is regular file
                regular_chmod
    ($file$chmod)
        
    endloop

    Thanks i'll work with that. I was hoping for a simpler solution. but i guess i'll have to work with it.
  8. #5
  9. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    364
    Rep Power
    12
    Originally Posted by Thr3ddy
    CHMOD 0777 is a bit drastic don't you think? This gives access to everybody and their grandma to delete, modify and upload files and directories...
    HA HA HA .. i guess i'll have to make it granny-proof!

    I am setting up a page where the user can upload images into a folder through their browser. I tried some options and couldnt get them to work. 777 worked
  10. #6
  11. No Profile Picture
    Redpill
    Devshed Intermediate (1500 - 1999 posts)

    Join Date
    Nov 2005
    Posts
    1,660
    Rep Power
    152
    Can't you just chmod the --folder-- to 0777, then create image files inside and chmod them so something more sane?

    Should the users be able to view the images directly? If not, just chmod everything to 0777 and .htaccess => Deny * from all
    Code:
    #include <stdio.h>
    int main(int o,char**O){return o>-1?o-2||!main(-1,1+O)?!!fprintf(stderr,"%s [0-"
    "9]{81}\n",*O):main(-83,++O):o>-83?(*O)[-1-o]?81==(o=-o-1)||o[*O]<'0'||'9'<o[*O]
    ?0:main(-2-o,O):o==-82:o>-164?(*O)[-83-o]<'1'?main(o-82,O):main(--o,O):o+164?o>-
    246?(*O)[-165-o]<'1'?main(o-82,O):main(--o,O):o+246?o>-328?(*O)[o=-o-247]<='8'?(
    main(-328-o,(++o[*O],O)),main(-247-o,O)):!(o[*O]='0'):(o=-o-328)<729?(o%9/3*3-o%
    27+o/243*9+o/81%3&&(*O)[o%81]==(*O)[o%81-o%27+o%9/3*3+o/243*9+o/81%3])||(o%81-o%
    9-o/81*9&&(*O)[o%81]==(*O)[o%9+o/81*9])||(o/81-o%9&&(*O)[o%81]==(*O)[o%81-o%9+o/
    81])?0:main(-409-o,O):main(-165-o%81,O):!puts(*O):0                           ;}
  12. #7
  13. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Mar 2003
    Posts
    364
    Rep Power
    12
    Originally Posted by jafet
    Can't you just chmod the --folder-- to 0777, then create image files inside and chmod them so something more sane?

    Should the users be able to view the images directly? If not, just chmod everything to 0777 and .htaccess => Deny * from all
    This is the set up. The client will upload the images into the folder usong their browser. I have CHMODed the folder to 777. The folder contains a only 1 CSV file (for now) that holds additional info regarding the image, in additon to all the images uploaded into it. When the pic is uploaded into the folder, the additional data is written to the CSV file.

    A link to the image and the additional info from the csv file is shown on the download page for the image only to be downloaded. I shall use your code to CHMOD the folder to 777 and look into that folder and only CHMOD the CSV file to enable data to be written to it.

IMN logo majestic logo threadwatch logo seochat tools logo