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 * remove the execute permission from the parent dir and test scandir() on child dir
19 * 1. remove write & execute permission from the 1st parent and test scandir()
20 * 2. remove execute permission from 2nd parent and test scandir()
21 */
22
23echo "*** Testing scandir() : usage variations ***\n";
24
25/*
26 * create the temporary directory :
27 * scandir_variation5  ( parent )
28 *  |-> sub_dir     ( sub parent )
29 *      |-> child_dir  ( child dir)
30 */
31
32$parent_dir_path = __DIR__ . "/scandir_variation5";
33mkdir($parent_dir_path);
34chmod($parent_dir_path, 0777);
35
36// create sub_dir
37$sub_dir_path = $parent_dir_path . "/sub_dir";
38mkdir($sub_dir_path);
39chmod($sub_dir_path, 0777);
40
41//create sub_sub_dir
42$child_dir_path = $sub_dir_path."/child_dir";
43mkdir($child_dir_path);
44
45// remove the write and execute permisson from sub parent
46chmod($sub_dir_path, 0444);
47
48echo "\n-- After restricting 1st level parent directory --\n";
49var_dump(scandir($child_dir_path));
50
51// remove the execute permisson from parent dir, allowing all permission for sub dir
52chmod($sub_dir_path, 0777); // all permisson to sub dir
53chmod($parent_dir_path, 0666); // restricting parent directory
54
55echo "\n-- After restricting parent directory --\n";
56var_dump(scandir($child_dir_path));
57?>
58===DONE===
59--CLEAN--
60<?php
61$parent_dir_path = __DIR__ . "/scandir_variation5";
62$sub_dir_path = $parent_dir_path."/sub_dir";
63$child_dir_path = $sub_dir_path."/child_dir";
64
65// changing permissions for each temporary directory to delete them
66chmod($parent_dir_path, 0777);
67chmod($sub_dir_path, 0777);
68chmod($child_dir_path, 0777);
69
70rmdir($child_dir_path);
71rmdir($sub_dir_path);
72rmdir($parent_dir_path);
73?>
74--EXPECTF--
75*** Testing scandir() : usage variations ***
76
77-- After restricting 1st level parent directory --
78
79Warning: scandir(%s/scandir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d
80
81Warning: scandir(): (errno %d): %s in %s on line %d
82bool(false)
83
84-- After restricting parent directory --
85
86Warning: scandir(%s/scandir_variation5/sub_dir/child_dir): failed to open dir: %s in %s on line %d
87
88Warning: scandir(): (errno %d): %s in %s on line %d
89bool(false)
90===DONE===
91