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