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