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