1--TEST-- 2Test scandir() function : usage variations - different directory permissions 3--SKIPIF-- 4<?php 5if( substr(PHP_OS, 0, 3) == 'WIN') { 6 die('skip Not for Windows'); 7} 8require __DIR__ . '/../skipif_root.inc'; 9?> 10--FILE-- 11<?php 12/* Prototype : array scandir(string $dir [, int $sorting_order [, resource $context]]) 13 * Description: List files & directories inside the specified path 14 * Source code: ext/standard/dir.c 15 */ 16 17/* 18 * Create directories with different permissions to test whether scandir() can access them 19 */ 20 21echo "*** Testing scandir() : usage variations ***\n"; 22 23// create the temporary directory 24$dir_path = __DIR__ . "/scandir_variation7"; 25mkdir($dir_path); 26 27// different values for directory permissions 28$permission_values = array( 29/*1*/ 0477, // owner has read only, other and group has rwx 30 0677, // owner has rw only, other and group has rwx 31 32/*3*/ 0444, // all have read only 33 0666, // all have rw only 34 35/*5*/ 0400, // owner has read only, group and others have no permission 36 0600, // owner has rw only, group and others have no permission 37 38/*7*/ 0470, // owner has read only, group has rwx & others have no permission 39 0407, // owner has read only, other has rwx & group has no permission 40 41/*9*/ 0670, // owner has rw only, group has rwx & others have no permission 42/*10*/ 0607 // owner has rw only, group has no permission and others have rwx 43); 44 45$iterator = 1; 46foreach ($permission_values as $perm) { 47 echo "\n-- Iteration $iterator --\n"; 48 49 // Remove the directory if already exists 50 if (is_dir($dir_path)){ 51 chmod ($dir_path, 0777); // change dir permission to allow all operation 52 rmdir ($dir_path); 53 } 54 mkdir($dir_path); 55 56 // change the dir permisson to test dir on it 57 var_dump( chmod($dir_path, $perm) ); 58 59 var_dump(scandir($dir_path)); 60 $iterator++; 61} 62?> 63===DONE=== 64--CLEAN-- 65<?php 66$dir_path = __DIR__ . "/scandir_variation7"; 67rmdir($dir_path); 68?> 69--EXPECT-- 70*** Testing scandir() : usage variations *** 71 72-- Iteration 1 -- 73bool(true) 74array(2) { 75 [0]=> 76 string(1) "." 77 [1]=> 78 string(2) ".." 79} 80 81-- Iteration 2 -- 82bool(true) 83array(2) { 84 [0]=> 85 string(1) "." 86 [1]=> 87 string(2) ".." 88} 89 90-- Iteration 3 -- 91bool(true) 92array(2) { 93 [0]=> 94 string(1) "." 95 [1]=> 96 string(2) ".." 97} 98 99-- Iteration 4 -- 100bool(true) 101array(2) { 102 [0]=> 103 string(1) "." 104 [1]=> 105 string(2) ".." 106} 107 108-- Iteration 5 -- 109bool(true) 110array(2) { 111 [0]=> 112 string(1) "." 113 [1]=> 114 string(2) ".." 115} 116 117-- Iteration 6 -- 118bool(true) 119array(2) { 120 [0]=> 121 string(1) "." 122 [1]=> 123 string(2) ".." 124} 125 126-- Iteration 7 -- 127bool(true) 128array(2) { 129 [0]=> 130 string(1) "." 131 [1]=> 132 string(2) ".." 133} 134 135-- Iteration 8 -- 136bool(true) 137array(2) { 138 [0]=> 139 string(1) "." 140 [1]=> 141 string(2) ".." 142} 143 144-- Iteration 9 -- 145bool(true) 146array(2) { 147 [0]=> 148 string(1) "." 149 [1]=> 150 string(2) ".." 151} 152 153-- Iteration 10 -- 154bool(true) 155array(2) { 156 [0]=> 157 string(1) "." 158 [1]=> 159 string(2) ".." 160} 161===DONE=== 162