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