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