1--TEST-- 2Test file_get_contents() function : variation - various absolute and relative paths 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--FILE-- 6<?php 7echo "*** Testing file_get_contents() : variation ***\n"; 8$mainDir = "fileGetContentsVar7.dir"; 9$subDir = "fileGetContentsVar7Sub"; 10$absMainDir = __DIR__."/".$mainDir; 11mkdir($absMainDir); 12$absSubDir = $absMainDir."/".$subDir; 13mkdir($absSubDir); 14 15$old_dir_path = getcwd(); 16chdir(__DIR__); 17 18$allDirs = array( 19 // absolute paths 20 "$absSubDir/", 21 "$absSubDir/../".$subDir, 22 "$absSubDir//.././".$subDir, 23 "$absSubDir/../../".$mainDir."/./".$subDir, 24 "$absSubDir/..///".$subDir."//..//../".$subDir, 25 "$absSubDir/BADDIR", 26 27 // relative paths 28 $mainDir."/".$subDir, 29 $mainDir."//".$subDir, 30 $mainDir."///".$subDir, 31 "./".$mainDir."/../".$mainDir."/".$subDir, 32 "BADDIR", 33 34); 35 36$filename = 'FileGetContentsVar7.tmp'; 37$absFile = $absSubDir.'/'.$filename; 38$h = fopen($absFile,"w"); 39fwrite($h, "contents read"); 40fclose($h); 41 42for($i = 0; $i<count($allDirs); $i++) { 43 $j = $i+1; 44 $dir = $allDirs[$i]; 45 echo "\n-- Iteration $j --\n"; 46 var_dump(file_get_contents($dir."/".$filename)); 47} 48 49chdir($old_dir_path); 50unlink($absFile); 51rmdir($absSubDir); 52rmdir($absMainDir); 53 54echo "\n*** Done ***\n"; 55?> 56--EXPECTF-- 57*** Testing file_get_contents() : variation *** 58 59-- Iteration 1 -- 60string(%d) "contents read" 61 62-- Iteration 2 -- 63string(%d) "contents read" 64 65-- Iteration 3 -- 66string(%d) "contents read" 67 68-- Iteration 4 -- 69string(%d) "contents read" 70 71-- Iteration 5 -- 72 73Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/..///fileGetContentsVar7Sub//..//../fileGetContentsVar7Sub/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d 74bool(false) 75 76-- Iteration 6 -- 77 78Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/BADDIR/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d 79bool(false) 80 81-- Iteration 7 -- 82string(%d) "contents read" 83 84-- Iteration 8 -- 85string(%d) "contents read" 86 87-- Iteration 9 -- 88string(%d) "contents read" 89 90-- Iteration 10 -- 91string(%d) "contents read" 92 93-- Iteration 11 -- 94 95Warning: file_get_contents(BADDIR/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d 96bool(false) 97 98*** Done *** 99