2
Test opendir() function : usage variations - different directory permissions
5
if( substr(PHP_OS, 0, 3) == 'WIN') {
6
die('skip Not for Windows');
8
// Skip if being run by root (files are always readable, writeable and executable)
9
$filename = dirname(__FILE__) . "/opendir_root_check.tmp";
10
$fp = fopen($filename, 'w');
12
if(fileowner($filename) == 0) {
14
die('skip...cannot be run as root\n');
20
/* Prototype : mixed opendir(string $path[, resource $context])
21
* Description: Open a directory and return a dir_handle
22
* Source code: ext/standard/dir.c
26
* Open a directory using opendir() with different directory permissions
29
echo "*** Testing opendir() : usage variations ***\n";
31
// create the temporary directory
32
$file_path = dirname(__FILE__);
33
$dir_path = $file_path . "/opendir_variation7";
36
/* different values for directory permissions */
37
$permission_values = array(
38
/*1*/ 0477, // owner has read only, other and group has rwx
39
0677, // owner has rw only, other and group has rwx
41
/*3*/ 0444, // all have read only
42
0666, // all have rw only
44
/*5*/ 0400, // owner has read only, group and others have no permission
45
0600, // owner has rw only, group and others have no permission
47
/*7*/ 0470, // owner has read only, group has rwx & others have no permission
48
0407, // owner has read only, other has rwx & group has no permission
50
/*9*/ 0670, // owner has rw only, group has rwx & others have no permission
51
/*10*/ 0607 // owner has rw only, group has no permission and others have rwx
54
// Open directory with different permission values, read and close, expected: none of them to succeed.
57
foreach ($permission_values as $perm) {
59
echo "\n-- Iteration $iterator --\n";
60
// try to remove the dir if exists & create
61
if (is_dir($dir_path)){
62
chmod ($dir_path, 0777); // change dir permission to allow all operation
67
// change the dir permisson to test dir on it
68
var_dump( chmod($dir_path, $perm) );
70
var_dump($dh = opendir($dir_path));
72
if (is_resource($dh)) {
81
// deleting temporary directory
82
$dir_path = dirname(__FILE__) . "/opendir_variation7";
86
*** Testing opendir() : usage variations ***
90
resource(%d) of type (stream)
94
resource(%d) of type (stream)
98
resource(%d) of type (stream)
102
resource(%d) of type (stream)
106
resource(%d) of type (stream)
110
resource(%d) of type (stream)
114
resource(%d) of type (stream)
118
resource(%d) of type (stream)
122
resource(%d) of type (stream)
126
resource(%d) of type (stream)