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