1--TEST--
2Test file_get_contents() 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
12echo "*** Testing file_get_contents() : variation ***\n";
13$mainDir = "fileGetContentsVar7.dir";
14$subDir = "fileGetContentsVar7Sub";
15$absMainDir = __DIR__."\\".$mainDir;
16mkdir($absMainDir);
17$absSubDir = $absMainDir."\\".$subDir;
18mkdir($absSubDir);
19
20$old_dir_path = getcwd();
21chdir(__DIR__);
22$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3);
23
24$allDirs = array(
25  // absolute paths
26  "$absSubDir\\",
27  "$absSubDir\\..\\".$subDir,
28  "$absSubDir\\\\..\\.\\".$subDir,
29  "$absSubDir\\..\\..\\".$mainDir."\\.\\".$subDir,
30  "$absSubDir\\..\\\\\\".$subDir."\\\\..\\\\..\\".$subDir,
31  "$absSubDir\\BADDIR",
32
33  // relative paths
34  $mainDir."\\".$subDir,
35  $mainDir."\\\\".$subDir,
36   $mainDir."\\\\\\".$subDir,
37  ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir,
38  "BADDIR",
39
40  // unixifed path
41  $unixifiedDir,
42);
43
44$filename = 'FileGetContentsVar7.tmp';
45$absFile = $absSubDir.'/'.$filename;
46$h = fopen($absFile,"w");
47fwrite($h, "contents read");
48fclose($h);
49
50for($i = 0; $i<count($allDirs); $i++) {
51  $j = $i+1;
52  $dir = $allDirs[$i];
53  echo "\n-- Iteration $j --\n";
54  var_dump(file_get_contents($dir."\\".$filename));
55}
56
57unlink($absFile);
58chdir($old_dir_path);
59rmdir($absSubDir);
60rmdir($absMainDir);
61
62echo "\n*** Done ***\n";
63?>
64--EXPECTF--
65*** Testing file_get_contents() : variation ***
66
67-- Iteration 1 --
68string(%d) "contents read"
69
70-- Iteration 2 --
71string(%d) "contents read"
72
73-- Iteration 3 --
74string(%d) "contents read"
75
76-- Iteration 4 --
77string(%d) "contents read"
78
79-- Iteration 5 --
80
81Warning: file_get_contents(%sfileGetContentsVar7.dir\fileGetContentsVar7Sub\..\\\fileGetContentsVar7Sub\\..\\..\fileGetContentsVar7Sub\FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
82bool(false)
83
84-- Iteration 6 --
85
86Warning: file_get_contents(%sfileGetContentsVar7.dir\fileGetContentsVar7Sub\BADDIR\FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
87bool(false)
88
89-- Iteration 7 --
90string(%d) "contents read"
91
92-- Iteration 8 --
93string(%d) "contents read"
94
95-- Iteration 9 --
96string(%d) "contents read"
97
98-- Iteration 10 --
99string(%d) "contents read"
100
101-- Iteration 11 --
102
103Warning: file_get_contents(BADDIR\FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
104bool(false)
105
106-- Iteration 12 --
107string(%d) "contents read"
108
109*** Done ***
110