1--TEST--
2Test file function : variation - various absolute and relative paths
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--FILE--
6<?php
7echo "*** Testing file() : variation ***\n";
8$mainDir = "fileVar8.dir";
9$subDir = "fileVar8Sub";
10$absMainDir = __DIR__."/".$mainDir;
11mkdir($absMainDir);
12$absSubDir = $absMainDir."/".$subDir;
13mkdir($absSubDir);
14
15$old_dir_path = getcwd();
16chdir(__DIR__);
17
18$allDirs = array(
19  // absolute paths
20  "$absSubDir/",
21  "$absSubDir/../".$subDir,
22  "$absSubDir//.././".$subDir,
23  "$absSubDir/../../".$mainDir."/./".$subDir,
24  "$absSubDir/..///".$subDir."//..//../".$subDir,
25  "$absSubDir/BADDIR",
26
27  // relative paths
28  $mainDir."/".$subDir,
29  $mainDir."//".$subDir,
30   $mainDir."///".$subDir,
31  "./".$mainDir."/../".$mainDir."/".$subDir,
32  "BADDIR",
33
34);
35
36$filename = 'FileGetContentsVar7.tmp';
37$absFile = $absSubDir.'/'.$filename;
38$h = fopen($absFile,"w");
39fwrite($h, "contents read");
40fclose($h);
41
42for($i = 0; $i<count($allDirs); $i++) {
43  $j = $i+1;
44  $dir = $allDirs[$i];
45  echo "\n-- Iteration $j --\n";
46  var_dump(file($dir."/".$filename));
47}
48
49chdir($old_dir_path);
50
51echo "\n*** Done ***\n";
52?>
53--CLEAN--
54<?php
55$mainDir = "fileVar8.dir";
56$subDir = "fileVar8Sub";
57$absMainDir = __DIR__."/".$mainDir;
58$absSubDir = $absMainDir."/".$subDir;
59$filename = 'FileGetContentsVar7.tmp';
60$absFile = $absSubDir.'/'.$filename;
61unlink($absFile);
62rmdir($absSubDir);
63rmdir($absMainDir);
64?>
65--EXPECTF--
66*** Testing file() : variation ***
67
68-- Iteration 1 --
69array(1) {
70  [0]=>
71  string(13) "contents read"
72}
73
74-- Iteration 2 --
75array(1) {
76  [0]=>
77  string(13) "contents read"
78}
79
80-- Iteration 3 --
81array(1) {
82  [0]=>
83  string(13) "contents read"
84}
85
86-- Iteration 4 --
87array(1) {
88  [0]=>
89  string(13) "contents read"
90}
91
92-- Iteration 5 --
93
94Warning: file(%sfileVar8.dir/fileVar8Sub/..///fileVar8Sub//..//../fileVar8Sub/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
95bool(false)
96
97-- Iteration 6 --
98
99Warning: file(%sfileVar8.dir/fileVar8Sub/BADDIR/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
100bool(false)
101
102-- Iteration 7 --
103array(1) {
104  [0]=>
105  string(13) "contents read"
106}
107
108-- Iteration 8 --
109array(1) {
110  [0]=>
111  string(13) "contents read"
112}
113
114-- Iteration 9 --
115array(1) {
116  [0]=>
117  string(13) "contents read"
118}
119
120-- Iteration 10 --
121array(1) {
122  [0]=>
123  string(13) "contents read"
124}
125
126-- Iteration 11 --
127
128Warning: file(BADDIR/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
129bool(false)
130
131*** Done ***
132