Monday, January 16, 2012

How to fix permissions for files on a server?

Often after you upload files on a server you will get to the point when you won't be able to edit/delete add other files. It happened to me when I unzipped an archive directly on server with a php file.
So how do we change attributes?


set_time_limit ( 0 );
ini_set("memory_limit","1000M");

file_fix_directory(dirname(__FILE__));

function file_fix_directory($dir, $nomask = array('.', '..', 'CVS')) {
  if (is_dir($dir)) {
     // Try to make each directory world writable.
     if (@chmod($dir, 0777)) {
       echo "

Made writable: " . $dir . "

"; } } if (is_dir($dir) && $handle = opendir($dir)) { while (false !== ($file = readdir($handle))) { if (!in_array($file, $nomask) && $file[0] != '.') { if (is_dir("$dir/$file")) { // Recurse into subdirectories file_fix_directory("$dir/$file", $nomask); } else { $filename = "$dir/$file"; // Try to make each file world writable. if (@chmod($filename, 0777)) { echo "

Made writable: " . $filename . "

"; } } } } closedir($handle); } }

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. nota 10 pentru initiativa in scop educativ !
    categoriile HTML, PHP, CSS, JAVASCRIPT cele mai faine
    adauga pe ele sa putem face reclama :-)

    ReplyDelete
  3. incercam, incercam, trebuie putin timp doar...:P poate vrei sa colaborezi :-?

    ReplyDelete