This article mainly introduces PHP's method of recursively executing the chmod command on folders, which can realize the function of recursively executing the chmod command to change the folder's execution permission. For more information, see
This article mainly introduces PHP's method of recursively executing the chmod command on folders, which can realize the function of recursively executing the chmod command to change the folder's execution permission. For more information, see
This example describes how PHP recursively executes the chmod command on folders. Share it with you for your reference. The specific analysis is as follows:
Here, the chmod command is run recursively on folders and files to change the execution permission.
<? Php function recursiveChmod ($ path, $ filePerm = 0644, $ dirPerm = 0755) {// Check if the path existsif (! File_exists ($ path) {return (FALSE);} // See whether this is a fileif (is_file ($ path )) {// Chmod the file with our given filepermissionschmod ($ 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 $ Entry) {// And call this function again recursively, with the same permissionsrecursiveChmod ($ path. "http://www.jb51.net /". $ entry, $ filePerm, $ dirPerm);} // When we are done with the contents of the directory, we chmod the directory itselfchmod ($ path, $ dirPerm );} // Everything seemed to work out well, return TRUEreturn (TRUE);}?>
I hope this article will help you with php programming.
,