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 7/* Prototype : string file_get_contents(string filename [, bool use_include_path [, resource context [, long offset [, long maxlen]]]]) 8 * Description: Read the entire file into a string 9 * Source code: ext/standard/file.c 10 * Alias to functions: 11 */ 12 13echo "*** Testing file_get_contents() : variation ***\n"; 14$mainDir = "fileGetContentsVar7.dir"; 15$subDir = "fileGetContentsVar7Sub"; 16$absMainDir = dirname(__FILE__)."/".$mainDir; 17mkdir($absMainDir); 18$absSubDir = $absMainDir."/".$subDir; 19mkdir($absSubDir); 20 21$old_dir_path = getcwd(); 22chdir(dirname(__FILE__)); 23 24$allDirs = array( 25 // absolute paths 26 "$absSubDir/", 27 "$absSubDir/../".$subDir, 28 "$absSubDir//.././".$subDir, 29 "$absSubDir/../../".$mainDir."/./".$subDir, 30 "$absSubDir/..///".$subDir."//..//../".$subDir, 31 "$absSubDir/BADDIR", 32 33 // relative paths 34 $mainDir."/".$subDir, 35 $mainDir."//".$subDir, 36 $mainDir."///".$subDir, 37 "./".$mainDir."/../".$mainDir."/".$subDir, 38 "BADDIR", 39 40); 41 42$filename = 'FileGetContentsVar7.tmp'; 43$absFile = $absSubDir.'/'.$filename; 44$h = fopen($absFile,"w"); 45fwrite($h, "contents read"); 46fclose($h); 47 48for($i = 0; $i<count($allDirs); $i++) { 49 $j = $i+1; 50 $dir = $allDirs[$i]; 51 echo "\n-- Iteration $j --\n"; 52 var_dump(file_get_contents($dir."/".$filename)); 53} 54 55chdir($old_dir_path); 56unlink($absFile); 57rmdir($absSubDir); 58rmdir($absMainDir); 59 60echo "\n*** Done ***\n"; 61?> 62--EXPECTF-- 63*** Testing file_get_contents() : variation *** 64 65-- Iteration 1 -- 66string(%d) "contents read" 67 68-- Iteration 2 -- 69string(%d) "contents read" 70 71-- Iteration 3 -- 72string(%d) "contents read" 73 74-- Iteration 4 -- 75string(%d) "contents read" 76 77-- Iteration 5 -- 78 79Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/..///fileGetContentsVar7Sub//..//../fileGetContentsVar7Sub/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d 80bool(false) 81 82-- Iteration 6 -- 83 84Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d 85bool(false) 86 87-- Iteration 7 -- 88string(%d) "contents read" 89 90-- Iteration 8 -- 91string(%d) "contents read" 92 93-- Iteration 9 -- 94string(%d) "contents read" 95 96-- Iteration 10 -- 97string(%d) "contents read" 98 99-- Iteration 11 -- 100 101Warning: file_get_contents(BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d 102bool(false) 103 104*** Done *** 105