1--TEST--
2Test file_get_contents() function : variation - various absolute and relative paths
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--FILE--
6<?php
7echo "*** Testing file_get_contents() : variation ***\n";
8$mainDir = "fileGetContentsVar7.dir";
9$subDir = "fileGetContentsVar7Sub";
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_get_contents($dir."/".$filename));
47}
48
49chdir($old_dir_path);
50
51echo "\n*** Done ***\n";
52?>
53--CLEAN--
54<?php
55$mainDir = "fileGetContentsVar7.dir";
56$subDir = "fileGetContentsVar7Sub";
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_get_contents() : variation ***
67
68-- Iteration 1 --
69string(%d) "contents read"
70
71-- Iteration 2 --
72string(%d) "contents read"
73
74-- Iteration 3 --
75string(%d) "contents read"
76
77-- Iteration 4 --
78string(%d) "contents read"
79
80-- Iteration 5 --
81
82Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/..///fileGetContentsVar7Sub//..//../fileGetContentsVar7Sub/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
83bool(false)
84
85-- Iteration 6 --
86
87Warning: file_get_contents(%sfileGetContentsVar7.dir/fileGetContentsVar7Sub/BADDIR/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
88bool(false)
89
90-- Iteration 7 --
91string(%d) "contents read"
92
93-- Iteration 8 --
94string(%d) "contents read"
95
96-- Iteration 9 --
97string(%d) "contents read"
98
99-- Iteration 10 --
100string(%d) "contents read"
101
102-- Iteration 11 --
103
104Warning: file_get_contents(BADDIR/FileGetContentsVar7.tmp): Failed to open stream: No such file or directory in %s on line %d
105bool(false)
106
107*** Done ***
108