>  기사  >  백엔드 개발  >  PHP의 폴더에서 chmod 명령을 재귀적으로 실행하는 방법에 대한 자세한 설명

PHP의 폴더에서 chmod 명령을 재귀적으로 실행하는 방법에 대한 자세한 설명

怪我咯
怪我咯원래의
2017-07-05 10:26:121420검색

이 글에서는 주로 폴더에서 chmod 명령을 재귀적으로 실행하는 방법을 소개합니다. chmod 명령을 재귀적으로 실행하여 폴더의 실행 권한을 변경하는 기능을 구현할 수 있습니다.

이 글을 참조하세요. 기사에서는 chmod 명령을 재귀적으로 실행하는 방법 폴더에 있는 PHP의 예를 설명합니다. 참고할 수 있도록 모든 사람과 공유하세요. 구체적인 분석은 다음과 같습니다.

여기서 폴더 및 파일에 대해 chmod 명령을 반복적으로 실행하여 실행 권한을 변경합니다

<?php
  function recursiveChmod($path, $filePerm=0644, $dirPerm=0755)
  {
   // Check if the path exists
   if(!file_exists($path))
   {
     return(FALSE);
   }
   // See whether this is a file
   if(is_file($path))
   {
     // Chmod the file with our given filepermissions
     chmod($path, $filePerm);
   // If this is a directory...
   } elseif(is_dir($path)) {
     // Then get an array of the contents
     $foldersAndFiles = scandir($path);
     // Remove "." and ".." from the list
     $entries = array_slice($foldersAndFiles, 2);
     // Parse every result...
     foreach($entries as $entry)
     {
      // And call this function again recursively, with the same permissions
      recursiveChmod($path."/".$entry, $filePerm, $dirPerm);
     }
     // When we are done with the contents of the directory, we chmod the directory itself
     chmod($path, $dirPerm);
   }
   // Everything seemed to work out well, return TRUE
   return(TRUE);
  }
?>

위 내용은 PHP의 폴더에서 chmod 명령을 재귀적으로 실행하는 방법에 대한 자세한 설명의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.