1--TEST-- 2Test opendir() function : usage variations - different relative paths 3--SKIPIF-- 4<?php 5if (substr(PHP_OS, 0, 3) != 'WIN') { 6 die("skip Valid only on Windows"); 7} 8?> 9--FILE-- 10<?php 11/* Prototype : mixed opendir(string $path[, resource $context]) 12 * Description: Open a directory and return a dir_handle 13 * Source code: ext/standard/dir.c 14 */ 15 16/* 17 * Test opendir() with different relative paths as $path argument 18 */ 19 20echo "*** Testing opendir() : usage variation ***\n"; 21 22$base_dir_path = dirname(__FILE__); 23 24$level_one_dir_name = "私はガラスを食べられますlevel_one"; 25$level_one_dir_path = "$base_dir_path/$level_one_dir_name"; 26 27$level_two_dir_name = "私はガラスを食べられますlevel_two"; 28$level_two_dir_path = "$base_dir_path/$level_one_dir_name/$level_two_dir_name"; 29 30// create directories 31mkdir($level_one_dir_path); 32mkdir($level_two_dir_path); 33 34echo "\n-- \$path = './私はガラスを食べられますlevel_one': --\n"; 35var_dump(chdir($base_dir_path)); 36var_dump($dh = opendir("./$level_one_dir_name")); 37clean_dh($dh); 38 39echo "\n-- \$path = '私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two': --\n"; 40var_dump(chdir($base_dir_path)); 41var_dump($dh = opendir("$level_one_dir_name/$level_two_dir_name")); 42clean_dh($dh); 43 44echo "\n-- \$path = '..': --\n"; 45var_dump($dh = opendir('..')); 46clean_dh($dh); 47 48echo "\n-- \$path = 'level_two', '.': --\n"; 49var_dump(chdir($level_two_dir_path)); 50var_dump($dh = opendir('.')); 51clean_dh($dh); 52 53echo "\n-- \$path = '../': --\n"; 54var_dump($dh = opendir('../')); 55clean_dh($dh); 56 57echo "\n-- \$path = './': --\n"; 58var_dump(chdir($level_two_dir_path)); 59var_dump($dh = opendir('./')); 60clean_dh($dh); 61 62echo "\n-- \$path = '../../'私はガラスを食べられますlevel_one': --\n"; 63var_dump(chdir($level_two_dir_path)); 64var_dump($dh = opendir("../../$level_one_dir_name")); 65clean_dh($dh); 66 67/* 68 * function to remove directory handle before re-using variable name in test 69 * and to ensure directory is not in use at CLEAN section so can me removed 70 */ 71function clean_dh($dh){ 72 if (is_resource($dh)) { 73 closedir($dh); 74 } 75 unset($dh); 76} 77?> 78===DONE=== 79--CLEAN-- 80<?php 81$file_path = dirname(__FILE__); 82rmdir("$file_path/私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two"); 83rmdir("$file_path/私はガラスを食べられますlevel_one"); 84?> 85--EXPECTF-- 86*** Testing opendir() : usage variation *** 87 88-- $path = './私はガラスを食べられますlevel_one': -- 89bool(true) 90resource(%d) of type (stream) 91 92-- $path = '私はガラスを食べられますlevel_one/私はガラスを食べられますlevel_two': -- 93bool(true) 94resource(%d) of type (stream) 95 96-- $path = '..': -- 97resource(%d) of type (stream) 98 99-- $path = 'level_two', '.': -- 100bool(true) 101resource(%d) of type (stream) 102 103-- $path = '../': -- 104resource(%d) of type (stream) 105 106-- $path = './': -- 107bool(true) 108resource(%d) of type (stream) 109 110-- $path = '../../'私はガラスを食べられますlevel_one': -- 111bool(true) 112resource(%d) of type (stream) 113===DONE=== 114