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