1--TEST-- 2Test fopen() function : variation: file uri, use include path = true 3--CREDITS-- 4Dave Kelsey <d_kelsey@uk.ibm.com> 5--SKIPIF-- 6<?php 7if(substr(PHP_OS, 0, 3) == "WIN") 8 die("skip Not for Windows"); 9?> 10--FILE-- 11<?php 12/* Prototype : resource fopen(string filename, string mode [, bool use_include_path [, resource context]]) 13 * Description: Open a file or a URL and return a file pointer 14 * Source code: ext/standard/file.c 15 * Alias to functions: 16 */ 17 18echo "*** Testing fopen() : variation ***\n"; 19 20// fopen with interesting windows paths. 21$includePathDir = getcwd().'/fopen15.includeDir'; 22$testDir = 'fopen15.tmpDir'; 23$absTestDir = getcwd().'/'.$testDir; 24$file = "fopen_variation15.tmp"; 25$absFile = $absTestDir.'/'.$file; 26 27mkdir($testDir); 28mkdir($includePathDir); 29set_include_path($includePathDir); 30 31$files = array("file://$testDir/$file", 32 "file://./$testDir/$file", 33 "file://$absTestDir/$file" 34); 35 36runtest($files); 37 38chdir($testDir); 39$files = array("file://../$testDir/$file", 40 "file://$absTestDir/$file" 41); 42runtest($files); 43chdir(".."); 44rmdir($testDir); 45rmdir($includePathDir); 46 47function runtest($fileURIs) { 48 global $absFile; 49 $iteration = 0; 50 foreach($fileURIs as $fileURI) { 51 echo "--- READ: $fileURI ---\n"; 52 53 $readData = "read:$iteration"; 54 $writeData = "write:$iteration"; 55 56 // create the file and test read 57 $h = fopen($absFile, 'w'); 58 fwrite($h, $readData); 59 fclose($h); 60 61 $h = fopen($fileURI, 'r', true); 62 if ($h !== false) { 63 if (fread($h, 4096) != $readData) { 64 echo "contents not correct\n"; 65 } 66 else { 67 echo "test passed\n"; 68 } 69 fclose($h); 70 } 71 unlink($absFile); 72 73 echo "--- WRITE: $fileURI ---\n"; 74 // create the file to test write 75 $h = fopen($fileURI, 'w', true); 76 if ($h !== false) { 77 fwrite($h, $writeData); 78 fclose($h); 79 80 $h = fopen($absFile, 'r'); 81 if ($h !== false) { 82 if (fread($h, 4096) != $writeData) { 83 echo "contents not correct\n"; 84 } 85 else { 86 echo "test passed\n"; 87 } 88 fclose($h); 89 } 90 unlink($absFile); 91 } 92 } 93} 94 95 96?> 97===DONE=== 98--EXPECTF-- 99*** Testing fopen() : variation *** 100--- READ: file://fopen15.tmpDir/fopen_variation15.tmp --- 101 102Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d 103 104Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 105--- WRITE: file://fopen15.tmpDir/fopen_variation15.tmp --- 106 107Warning: fopen(): remote host file access not supported, file://fopen15.tmpDir/fopen_variation15.tmp in %s on line %d 108 109Warning: fopen(file://fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 110--- READ: file://./fopen15.tmpDir/fopen_variation15.tmp --- 111 112Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d 113 114Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 115--- WRITE: file://./fopen15.tmpDir/fopen_variation15.tmp --- 116 117Warning: fopen(): remote host file access not supported, file://./fopen15.tmpDir/fopen_variation15.tmp in %s on line %d 118 119Warning: fopen(file://./fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 120--- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- 121test passed 122--- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- 123test passed 124--- READ: file://../fopen15.tmpDir/fopen_variation15.tmp --- 125 126Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d 127 128Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 129--- WRITE: file://../fopen15.tmpDir/fopen_variation15.tmp --- 130 131Warning: fopen(): remote host file access not supported, file://../fopen15.tmpDir/fopen_variation15.tmp in %s on line %d 132 133Warning: fopen(file://../fopen15.tmpDir/fopen_variation15.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 134--- READ: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- 135test passed 136--- WRITE: file:///%s/fopen15.tmpDir/fopen_variation15.tmp --- 137test passed 138===DONE===