1--TEST-- 2Test fopen() function : variation: use include path and stream context (absolute directories in path) 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--FILE-- 6<?php 7//create the include directory structure 8$thisTestDir = basename(__FILE__, ".php") . ".dir"; 9mkdir($thisTestDir); 10chdir($thisTestDir); 11 12$workingDir = "workdir"; 13$filename = basename(__FILE__, ".php") . ".tmp"; 14$scriptDir = __DIR__; 15$baseDir = getcwd(); 16$secondFile = $baseDir."/dir2/".$filename; 17$firstFile = "../dir1/".$filename; 18$scriptFile = $scriptDir.'/'.$filename; 19 20$newdirs = array("dir1", "dir2", "dir3"); 21$pathSep = ":"; 22$newIncludePath = ""; 23if(substr(PHP_OS, 0, 3) == 'WIN' ) { 24 $pathSep = ";"; 25} 26foreach($newdirs as $newdir) { 27 mkdir($newdir); 28 $newIncludePath .= $baseDir.'/'.$newdir.$pathSep; 29} 30mkdir($workingDir); 31chdir($workingDir); 32 33//define the files to go into these directories, create one in dir2 34echo "\n--- testing include path ---\n"; 35set_include_path($newIncludePath); 36$modes = array("r", "r+", "rt"); 37foreach($modes as $mode) { 38 test_fopen($mode); 39} 40 41// remove the directory structure 42chdir($baseDir); 43rmdir($workingDir); 44foreach($newdirs as $newdir) { 45 rmdir($newdir); 46} 47 48chdir(".."); 49rmdir($thisTestDir); 50 51 52function test_fopen($mode) { 53 global $scriptFile, $secondFile, $firstFile, $filename; 54 55 // create a file in the middle directory 56 $h = fopen($secondFile, "w"); 57 fwrite($h, "in dir2"); 58 fclose($h); 59 60 echo "\n** testing with mode=$mode **\n"; 61 // should read dir2 file 62 $h = fopen($filename, $mode, true); 63 fpassthru($h); 64 fclose($h); 65 echo "\n"; 66 67 //create a file in dir1 68 $h = fopen($firstFile, "w"); 69 fwrite($h, "in dir1"); 70 fclose($h); 71 72 //should now read dir1 file 73 $h = fopen($filename, $mode, true); 74 fpassthru($h); 75 fclose($h); 76 echo "\n"; 77 78 // create a file in working directory 79 $h = fopen($filename, "w"); 80 fwrite($h, "in working dir"); 81 fclose($h); 82 83 //should still read dir1 file 84 $h = fopen($filename, $mode, true); 85 fpassthru($h); 86 fclose($h); 87 echo "\n"; 88 89 unlink($firstFile); 90 unlink($secondFile); 91 92 //should read the file in working dir 93 $h = fopen($filename, $mode, true); 94 fpassthru($h); 95 fclose($h); 96 echo "\n"; 97 98 // create a file in the script directory 99 $h = fopen($scriptFile, "w"); 100 fwrite($h, "in script dir"); 101 fclose($h); 102 103 //should read the file in script dir 104 $h = fopen($filename, $mode, true); 105 fpassthru($h); 106 fclose($h); 107 echo "\n"; 108 109 //cleanup 110 unlink($filename); 111 unlink($scriptFile); 112 113} 114 115?> 116--EXPECT-- 117--- testing include path --- 118 119** testing with mode=r ** 120in dir2 121in dir1 122in dir1 123in working dir 124in script dir 125 126** testing with mode=r+ ** 127in dir2 128in dir1 129in dir1 130in working dir 131in script dir 132 133** testing with mode=rt ** 134in dir2 135in dir1 136in dir1 137in working dir 138in script dir 139