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