1--TEST-- 2Test readdir() function : usage variations - different 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/* 13 * Open a directory with different premissions then try to read it 14 * to test behaviour of readdir() 15 */ 16 17echo "*** Testing readdir() : usage variations ***\n"; 18 19// create the temporary directory 20$dir_path = __DIR__ . "/readdir_variation5"; 21mkdir($dir_path); 22 23/* different values for directory permissions */ 24$permission_values = array( 25/*1*/ 0477, // owner has read only, other and group has rwx 26 0677, // owner has rw only, other and group has rwx 27 28/*3*/ 0444, // all have read only 29 0666, // all have rw only 30 31/*5*/ 0400, // owner has read only, group and others have no permission 32 0600, // owner has rw only, group and others have no permission 33 34/*7*/ 0470, // owner has read only, group has rwx & others have no permission 35 0407, // owner has read only, other has rwx & group has no permission 36 37/*9*/ 0670, // owner has rw only, group has rwx & others have no permission 38/*10*/ 0607 // owner has rw only, group has no permission and others have rwx 39); 40 41// Open directory with different permission values, read and close, expected: none of them to succeed. 42$iterator = 1; 43foreach($permission_values as $perm) { 44 echo "\n-- Iteration $iterator --\n"; 45 46 if (is_dir($dir_path)) { 47 chmod ($dir_path, 0777); // change dir permission to allow all operation 48 rmdir ($dir_path); 49 } 50 mkdir($dir_path); 51 52 // change the dir permission to test dir on it 53 var_dump( chmod($dir_path, $perm) ); 54 var_dump($dh = opendir($dir_path)); 55 56 echo "-- Calling readdir() --\n"; 57 var_dump(readdir($dh)); 58 59 closedir($dh); 60 $iterator++; 61} 62?> 63--CLEAN-- 64<?php 65$dir_path = __DIR__ . "/readdir_variation5"; 66rmdir($dir_path); 67?> 68--EXPECTF-- 69*** Testing readdir() : usage variations *** 70 71-- Iteration 1 -- 72bool(true) 73resource(%d) of type (stream) 74-- Calling readdir() -- 75string(%d) "%s" 76 77-- Iteration 2 -- 78bool(true) 79resource(%d) of type (stream) 80-- Calling readdir() -- 81string(%d) "%s" 82 83-- Iteration 3 -- 84bool(true) 85resource(%d) of type (stream) 86-- Calling readdir() -- 87string(%d) "%s" 88 89-- Iteration 4 -- 90bool(true) 91resource(%d) of type (stream) 92-- Calling readdir() -- 93string(%d) "%s" 94 95-- Iteration 5 -- 96bool(true) 97resource(%d) of type (stream) 98-- Calling readdir() -- 99string(%d) "%s" 100 101-- Iteration 6 -- 102bool(true) 103resource(%d) of type (stream) 104-- Calling readdir() -- 105string(%d) "%s" 106 107-- Iteration 7 -- 108bool(true) 109resource(%d) of type (stream) 110-- Calling readdir() -- 111string(%d) "%s" 112 113-- Iteration 8 -- 114bool(true) 115resource(%d) of type (stream) 116-- Calling readdir() -- 117string(%d) "%s" 118 119-- Iteration 9 -- 120bool(true) 121resource(%d) of type (stream) 122-- Calling readdir() -- 123string(%d) "%s" 124 125-- Iteration 10 -- 126bool(true) 127resource(%d) of type (stream) 128-- Calling readdir() -- 129string(%d) "%s" 130