Annotation of embedaddon/php/ext/standard/tests/file/readfile_variation9.phpt, revision 1.1.1.1
1.1 misho 1: --TEST--
2: Test readfile() function : variation - variable types of path
3: --CREDITS--
4: Dave Kelsey <d_kelsey@uk.ibm.com>
5: --FILE--
6: <?php
7: /* Prototype : int readfile(string filename [, bool use_include_path[, resource context]])
8: * Description: Output a file or a URL
9: * Source code: ext/standard/file.c
10: * Alias to functions:
11: */
12:
13: echo "*** Testing readfile() : variation ***\n";
14: $mainDir = "readfileVar8";
15: $subDir = "readfileVar8Sub";
16: $absMainDir = dirname(__FILE__)."/".$mainDir;
17: mkdir($absMainDir);
18: $absSubDir = $absMainDir."/".$subDir;
19: mkdir($absSubDir);
20:
21: $theFile = "fileToRead.tmp";
22: $absFile = $absSubDir.'/'.$theFile;
23:
24: // create the file
25: $h = fopen($absFile,"w");
26: fwrite($h, "The File Contents");
27: fclose($h);
28:
29:
30: $old_dir_path = getcwd();
31: chdir(dirname(__FILE__));
32:
33: $allDirs = array(
34: // absolute paths
35: "$absSubDir/",
36: "$absSubDir/../".$subDir,
37: "$absSubDir//.././".$subDir,
38: "$absSubDir/../../".$mainDir."/./".$subDir,
39: "$absSubDir/..///".$subDir."//..//../".$subDir,
40: "$absSubDir/BADDIR",
41:
42:
43: // relative paths
44: $mainDir."/".$subDir,
45: $mainDir."//".$subDir,
46: $mainDir."///".$subDir,
47: "./".$mainDir."/../".$mainDir."/".$subDir,
48: "BADDIR",
49: );
50:
51: for($i = 0; $i<count($allDirs); $i++) {
52: $j = $i+1;
53: $dir = $allDirs[$i];
54: echo "\n-- Iteration $j --\n";
55: $ok = readfile($dir.'/'.$theFile);
56: if ($ok === 1) {
57: echo "\n";
58: }
59: }
60:
61: unlink($absFile);
62: chdir($old_dir_path);
63: rmdir($absSubDir);
64: rmdir($absMainDir);
65:
66: echo "\n*** Done ***\n";
67: ?>
68: --EXPECTF--
69: *** Testing readfile() : variation ***
70:
71: -- Iteration 1 --
72: The File Contents
73: -- Iteration 2 --
74: The File Contents
75: -- Iteration 3 --
76: The File Contents
77: -- Iteration 4 --
78: The File Contents
79: -- Iteration 5 --
80:
81: Warning: readfile(%sreadfileVar8Sub/..///readfileVar8Sub//..//../readfileVar8Sub/fileToRead.tmp): failed to open stream: No such file or directory in %s on line %d
82:
83: -- Iteration 6 --
84:
85: Warning: readfile(%sreadfileVar8Sub/BADDIR/fileToRead.tmp): failed to open stream: No such file or directory in %s on line %d
86:
87: -- Iteration 7 --
88: The File Contents
89: -- Iteration 8 --
90: The File Contents
91: -- Iteration 9 --
92: The File Contents
93: -- Iteration 10 --
94: The File Contents
95: -- Iteration 11 --
96:
97: Warning: readfile(BADDIR/fileToRead.tmp): failed to open stream: No such file or directory in %s on line %d
98:
99: *** Done ***
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>