1--TEST-- 2Test fopen() function : variation: file uri, no use include path 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$testDir = 'fopen14.tmpDir'; 22$absTestDir = getcwd().'/'.$testDir; 23$file = "fopen_variation14.tmp"; 24$absFile = $absTestDir.'/'.$file; 25 26mkdir($testDir); 27 28$files = array("file://$testDir/$file", 29 "file://./$testDir/$file", 30 "file://$absTestDir/$file" 31); 32 33runtest($files); 34 35chdir($testDir); 36$files = array("file://../$testDir/$file", 37 "file://$absTestDir/$file", 38); 39runtest($files); 40chdir(".."); 41rmdir($testDir); 42 43function runtest($fileURIs) { 44 global $absFile; 45 $iteration = 0; 46 foreach($fileURIs as $fileURI) { 47 echo "--- READ: $fileURI ---\n"; 48 49 $readData = "read:$iteration"; 50 $writeData = "write:$iteration"; 51 52 // create the file and test read 53 $h = fopen($absFile, 'w'); 54 fwrite($h, $readData); 55 fclose($h); 56 57 $h = fopen($fileURI, 'r'); 58 if ($h !== false) { 59 if (fread($h, 4096) != $readData) { 60 echo "contents not correct\n"; 61 } 62 else { 63 echo "test passed\n"; 64 } 65 fclose($h); 66 } 67 unlink($absFile); 68 69 echo "--- WRITE: $fileURI ---\n"; 70 // create the file to test write 71 $h = fopen($fileURI, 'w'); 72 if ($h !== false) { 73 fwrite($h, $writeData); 74 fclose($h); 75 76 $h = fopen($absFile, 'r'); 77 if ($h !== false) { 78 if (fread($h, 4096) != $writeData) { 79 echo "contents not correct\n"; 80 } 81 else { 82 echo "test passed\n"; 83 } 84 fclose($h); 85 } 86 unlink($absFile); 87 } 88 } 89} 90 91 92?> 93===DONE=== 94--EXPECTF-- 95*** Testing fopen() : variation *** 96--- READ: file://fopen14.tmpDir/fopen_variation14.tmp --- 97 98Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d 99 100Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 101--- WRITE: file://fopen14.tmpDir/fopen_variation14.tmp --- 102 103Warning: fopen(): remote host file access not supported, file://fopen14.tmpDir/fopen_variation14.tmp in %s on line %d 104 105Warning: fopen(file://fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 106--- READ: file://./fopen14.tmpDir/fopen_variation14.tmp --- 107 108Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d 109 110Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 111--- WRITE: file://./fopen14.tmpDir/fopen_variation14.tmp --- 112 113Warning: fopen(): remote host file access not supported, file://./fopen14.tmpDir/fopen_variation14.tmp in %s on line %d 114 115Warning: fopen(file://./fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 116--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- 117test passed 118--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- 119test passed 120--- READ: file://../fopen14.tmpDir/fopen_variation14.tmp --- 121 122Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d 123 124Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 125--- WRITE: file://../fopen14.tmpDir/fopen_variation14.tmp --- 126 127Warning: fopen(): remote host file access not supported, file://../fopen14.tmpDir/fopen_variation14.tmp in %s on line %d 128 129Warning: fopen(file://../fopen14.tmpDir/fopen_variation14.tmp): failed to open stream: no suitable wrapper could be found in %s on line %d 130--- READ: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- 131test passed 132--- WRITE: file:///%s/fopen14.tmpDir/fopen_variation14.tmp --- 133test passed 134===DONE=== 135