1--TEST-- 2Test file function : variation - various absolute and relative paths 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--FILE-- 6<?php 7/* Prototype : array file(string filename [, int flags[, resource context]]) 8 * Description: Read entire file into an array 9 * Source code: ext/standard/file.c 10 * Alias to functions: 11 */ 12 13echo "*** Testing file() : variation ***\n"; 14$mainDir = "fileVar8.dir"; 15$subDir = "fileVar8Sub"; 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($dir."/".$filename)); 53} 54 55unlink($absFile); 56chdir($old_dir_path); 57rmdir($absSubDir); 58rmdir($absMainDir); 59 60echo "\n*** Done ***\n"; 61?> 62--EXPECTF-- 63*** Testing file() : variation *** 64 65-- Iteration 1 -- 66array(1) { 67 [0]=> 68 string(13) "contents read" 69} 70 71-- Iteration 2 -- 72array(1) { 73 [0]=> 74 string(13) "contents read" 75} 76 77-- Iteration 3 -- 78array(1) { 79 [0]=> 80 string(13) "contents read" 81} 82 83-- Iteration 4 -- 84array(1) { 85 [0]=> 86 string(13) "contents read" 87} 88 89-- Iteration 5 -- 90 91Warning: file(%sfileVar8.dir/fileVar8Sub/..///fileVar8Sub//..//../fileVar8Sub/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d 92bool(false) 93 94-- Iteration 6 -- 95 96Warning: file(%sfileVar8.dir/fileVar8Sub/BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d 97bool(false) 98 99-- Iteration 7 -- 100array(1) { 101 [0]=> 102 string(13) "contents read" 103} 104 105-- Iteration 8 -- 106array(1) { 107 [0]=> 108 string(13) "contents read" 109} 110 111-- Iteration 9 -- 112array(1) { 113 [0]=> 114 string(13) "contents read" 115} 116 117-- Iteration 10 -- 118array(1) { 119 [0]=> 120 string(13) "contents read" 121} 122 123-- Iteration 11 -- 124 125Warning: file(BADDIR/FileGetContentsVar7.tmp): failed to open stream: No such file or directory in %s on line %d 126bool(false) 127 128*** Done ***