How to CHMOD multiple files at once

  • barry
  • Graduate
  • Graduate
  • User avatar
  • Posts: 115
  • Loc: scotland

Post 3+ Months Ago

HI

I am using this script to change the permissions of a file in a folder on my server

I cannot change the file permissions any other way , ive tried so please dont say @change to 777@ via cpanel or any other basic way as none of them are working

this is the script

<?php
chmod("/home/username/public_html/newsite/photos/1172088881.jpg", 755);

chmod("/home/username/public_html/newsite/photos/1172088881.jpg", "u+rwx,go+rx");
chmod("/home/username/public_html/newsite/photos/1172088881.jpg", 0755);

?>

This script will change the file permissions so i can simply download them one at a time but i need to mod this script to change the permissions of all the files in the photos folder in one go as there are hundreds of files there and doing them one at a time will take weeks

any help will be great
  • Anonymous
  • Bot
  • No Avatar
  • Posts: ?
  • Loc: Ozzuland
  • Status: Online

Post 3+ Months Ago

  • mo_mughrabi
  • Student
  • Student
  • User avatar
  • Posts: 73

Post 3+ Months Ago

try this:

Code: [ Select ]
<?php
exec("chmod 777 /full/path/*.jpg");
?>
  1. <?php
  2. exec("chmod 777 /full/path/*.jpg");
  3. ?>
  • AnarchY SI
  • Web Master
  • Web Master
  • User avatar
  • Posts: 2521
  • Loc: /usr/src/MI

Post 3+ Months Ago

or to better fit your sample,
Code: [ Select ]
<?php
exec("chmod 755 /home/username/public_html/newsite/photos/*.jpg");
?>
  1. <?php
  2. exec("chmod 755 /home/username/public_html/newsite/photos/*.jpg");
  3. ?>
  • barry
  • Graduate
  • Graduate
  • User avatar
  • Posts: 115
  • Loc: scotland

Post 3+ Months Ago

Shamow im dancing round my living room

thanks chaps that's probably the most useful bit of code ill get from any one this year !

and again i thank you all :lol:
  • exist
  • Born
  • Born
  • exist
  • Posts: 1

Post 3+ Months Ago

Code: [ Select ]
function setFolderPermitions($path = false)    {
        if (!$path)    {$path = $this->galleryPath;}
        clearstatcache ();
        $currdir = opendir($path);
        while ($file = readdir($currdir))    {
            if ($file != '.' && $file != '..')    {
                chmod ($path."/".$file,0777);
                if (is_dir($path."/".$file))    {
                    $this->setFolderPermitions($path."/".$file);
                }
            }
        }
    }
  1. function setFolderPermitions($path = false)    {
  2.         if (!$path)    {$path = $this->galleryPath;}
  3.         clearstatcache ();
  4.         $currdir = opendir($path);
  5.         while ($file = readdir($currdir))    {
  6.             if ($file != '.' && $file != '..')    {
  7.                 chmod ($path."/".$file,0777);
  8.                 if (is_dir($path."/".$file))    {
  9.                     $this->setFolderPermitions($path."/".$file);
  10.                 }
  11.             }
  12.         }
  13.     }

Post Information

  • Total Posts in this topic: 5 posts
  • Users browsing this forum: No registered users and 32 guests
  • You cannot post new topics in this forum
  • You cannot reply to topics in this forum
  • You cannot edit your posts in this forum
  • You cannot delete your posts in this forum
  • You cannot post attachments in this forum
 
 

© 1998-2014. Ozzu® is a registered trademark of Unmelted, LLC.