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