blob: 458d0b896f6d2bf91e0ed2c73d6ab39e6bd85157 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
|
--TEST--
Test dir() function : usage variations - relative valid and invalid paths
--SKIPIF--
<?php
if (substr(PHP_OS, 0, 3) == 'WIN') {
die('skip.. Not valid for Windows');
}
?>
--FILE--
<?php
/*
* Prototype : object dir(string $directory[, resource $context])
* Description: Directory class with properties, handle and class and methods read, rewind and close
* Source code: ext/standard/dir.c
*/
/*
* Checking the behavior of dir() function by passing directories which
* have valid and invalid relative path.
*/
echo "*** Testing dir() : checking with valid and invalid paths ***\n";
/* create the temporary directories */
$file_path = dirname(__FILE__);
// directory dir_variation91 with one sub-directory sub_dir11 and sub-sub-directory sub_dir111
$dir_path1 = $file_path."/dir_variation91";
$sub_dir11 = $dir_path1."/sub_dir11";
$sub_dir111 = $sub_dir11."/sub_dir111";
// directory dir_variation92 with one sub-directory sub_dir21
$dir_path2 = $file_path."/dir_variation92";
$sub_dir21 = $dir_path2."/sub_dir21";
@mkdir($dir_path1);
@mkdir($dir_path2);
@mkdir($sub_dir11);
@mkdir($sub_dir111);
@mkdir($sub_dir21);
// open the directory with valid paths
echo "\n-- With valid paths --\n";
var_dump( dir("$dir_path1/sub_dir11/sub_dir111/..") );
var_dump( dir("$dir_path2/sub_dir21/../../dir_variation91") );
var_dump( dir("$dir_path2/sub_dir21/../../dir_variation91/sub_dir11/..") );
var_dump( dir("$dir_path1/sub_dir11/sub_dir111/../../../dir_variation92/sub_dir21/..") );
// open the directory with invalid path
echo "\n-- With invalid paths --\n";
var_dump( dir("$dir_path1/sub_dir12/sub_dir111/..") );
var_dump( dir("$dir_path2/sub_dir21/../dir_variation91") );
var_dump( dir("$dir_path2/sub_dir21/../../dir_variation91/sub_dir12/..") );
var_dump( dir("$dir_path1/sub_dir11/sub_dir111/../../dir_variation92/sub_dir21/..") );
echo "Done";
?>
--CLEAN--
<?php
$file_path = dirname(__FILE__);
$dir_path1 = $file_path."/dir_variation91";
$sub_dir11 = $dir_path1."/sub_dir11";
$sub_dir111 = $sub_dir11."/sub_dir111";
$dir_path2 = $file_path."/dir_variation92";
$sub_dir21 = $dir_path2."/sub_dir21";
rmdir($sub_dir21);
rmdir($sub_dir111);
rmdir($sub_dir11);
rmdir($dir_path1);
rmdir($dir_path2);
?>
--EXPECTF--
*** Testing dir() : checking with valid and invalid paths ***
-- With valid paths --
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation91/sub_dir11/sub_dir111/.."
["handle"]=>
resource(%d) of type (stream)
}
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation92/sub_dir21/../../dir_variation91"
["handle"]=>
resource(%d) of type (stream)
}
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation92/sub_dir21/../../dir_variation91/sub_dir11/.."
["handle"]=>
resource(%d) of type (stream)
}
object(Directory)#%d (2) {
["path"]=>
string(%d) "%s/dir_variation91/sub_dir11/sub_dir111/../../../dir_variation92/sub_dir21/.."
["handle"]=>
resource(%d) of type (stream)
}
-- With invalid paths --
Warning: dir(%s/dir_variation91/sub_dir12/sub_dir111/..): failed to open dir: %s in %s on line %d
bool(false)
Warning: dir(%s/dir_variation92/sub_dir21/../dir_variation91): failed to open dir: %s in %s on line %d
bool(false)
Warning: dir(%s/dir_variation92/sub_dir21/../../dir_variation91/sub_dir12/..): failed to open dir: %s in %s on line %d
bool(false)
Warning: dir(%s/dir_variation91/sub_dir11/sub_dir111/../../dir_variation92/sub_dir21/..): failed to open dir: %s in %s on line %d
bool(false)
Done
|