1--TEST-- 2Test realpath() with relative paths 3--FILE-- 4<?php 5echo "\n*** Testing basic functions of realpath() with files ***\n"; 6 7/* creating directories and files */ 8$file_path = __DIR__; 9mkdir("$file_path/realpath_basic3/home/test/", 0777, true); 10 11$file_handle1 = fopen("$file_path/realpath_basic3/home/test/realpath_basic3.tmp", "w"); 12$file_handle2 = fopen("$file_path/realpath_basic3/home/realpath_basic3.tmp", "w"); 13$file_handle3 = fopen("$file_path/realpath_basic3/realpath_basic3.tmp", "w"); 14fclose($file_handle1); 15fclose($file_handle2); 16fclose($file_handle3); 17 18echo "\n*** Testing realpath() on filenames ***\n"; 19$filenames = array ( 20 /* filenames resulting in valid paths */ 21 "./realpath_basic3/home/realpath_basic3.tmp", 22 "./realpath_basic3/realpath_basic3.tmp", 23 "./realpath_basic3//home/test//../test/./realpath_basic3.tmp", 24 "./realpath_basic3/home//../././realpath_basic3.tmp", 25 26 /* filenames with invalid path */ 27 // checking for binary safe 28 "./realpath_basic3x000/home/realpath_basic3.tmp", 29 30 ".///realpath_basic3/home//..//././test//realpath_basic3.tmp", 31 "./realpath_basic3/home/../home/../test/..realpath_basic3.tmp" 32); 33 34chdir("$file_path/.."); 35chdir($file_path); 36 37$counter = 1; 38/* loop through $files to read the filepath of $file in the above array */ 39foreach($filenames as $file) { 40 echo "\n-- Iteration $counter --\n"; 41 var_dump( realpath($file) ); 42 $counter++; 43} 44 45echo "Done\n"; 46?> 47--CLEAN-- 48<?php 49$name_prefix = __DIR__."/realpath_basic3"; 50unlink("$name_prefix/home/test/realpath_basic3.tmp"); 51unlink("$name_prefix/home/realpath_basic3.tmp"); 52unlink("$name_prefix/realpath_basic3.tmp"); 53rmdir("$name_prefix/home/test/"); 54rmdir("$name_prefix/home/"); 55rmdir("$name_prefix/"); 56?> 57--EXPECTF-- 58*** Testing basic functions of realpath() with files *** 59 60*** Testing realpath() on filenames *** 61 62-- Iteration 1 -- 63string(%d) "%srealpath_basic3%shome%srealpath_basic3.tmp" 64 65-- Iteration 2 -- 66string(%d) "%srealpath_basic3%srealpath_basic3.tmp" 67 68-- Iteration 3 -- 69string(%d) "%srealpath_basic3%shome%stest%srealpath_basic3.tmp" 70 71-- Iteration 4 -- 72string(%d) "%srealpath_basic3%srealpath_basic3.tmp" 73 74-- Iteration 5 -- 75bool(false) 76 77-- Iteration 6 -- 78bool(false) 79 80-- Iteration 7 -- 81bool(false) 82Done 83