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
12echo "*** Testing readfile() : variation ***\n";
13$mainDir = "readfileVar8";
14$subDir = "readfileVar8Sub";
15$absMainDir = __DIR__."\\".$mainDir;
16mkdir($absMainDir);
17$absSubDir = $absMainDir."\\".$subDir;
18mkdir($absSubDir);
19
20$theFile = "fileToRead.tmp";
21$absFile = $absSubDir.'/'.$theFile;
22
23// create the file
24$h = fopen($absFile,"w");
25fwrite($h, "The File Contents");
26fclose($h);
27
28
29$old_dir_path = getcwd();
30chdir(__DIR__);
31$unixifiedDir = '/'.substr(str_replace('\\','/',$absSubDir),3);
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  // relative paths
43  $mainDir."\\".$subDir,
44  $mainDir."\\\\".$subDir,
45   $mainDir."\\\\\\".$subDir,
46  ".\\".$mainDir."\\..\\".$mainDir."\\".$subDir,
47  "BADDIR",
48
49  // unixifed path
50  $unixifiedDir,
51);
52
53for($i = 0; $i<count($allDirs); $i++) {
54  $j = $i+1;
55  $dir = $allDirs[$i];
56  echo "\n-- $dir --\n";
57  $ok = readfile($dir.'\\'.$theFile);
58  if ($ok === 1) {
59     echo "\n";
60  }
61}
62
63unlink($absFile);
64chdir($old_dir_path);
65rmdir($absSubDir);
66rmdir($absMainDir);
67
68echo "\n*** Done ***\n";
69?>
70--EXPECTF--
71*** Testing readfile() : variation ***
72
73-- %s\readfileVar8\readfileVar8Sub\ --
74The File Contents
75-- %s\readfileVar8\readfileVar8Sub\..\readfileVar8Sub --
76The File Contents
77-- %s\readfileVar8\readfileVar8Sub\\..\.\readfileVar8Sub --
78The File Contents
79-- %s\readfileVar8\readfileVar8Sub\..\..\readfileVar8\.\readfileVar8Sub --
80The File Contents
81-- %s\readfileVar8\readfileVar8Sub\..\\\readfileVar8Sub\\..\\..\readfileVar8Sub --
82
83Warning: readfile(%s\readfileVar8\readfileVar8Sub\..\\\readfileVar8Sub\\..\\..\readfileVar8Sub\fileToRead.tmp): Failed to open stream: No such file or directory in %s on line %d
84
85-- %s\readfileVar8\readfileVar8Sub\BADDIR --
86
87Warning: readfile(%s\readfileVar8\readfileVar8Sub\BADDIR\fileToRead.tmp): Failed to open stream: No such file or directory in %s on line %d
88
89-- readfileVar8\readfileVar8Sub --
90The File Contents
91-- readfileVar8\\readfileVar8Sub --
92The File Contents
93-- readfileVar8\\\readfileVar8Sub --
94The File Contents
95-- .\readfileVar8\..\readfileVar8\readfileVar8Sub --
96The File Contents
97-- BADDIR --
98
99Warning: readfile(BADDIR\fileToRead.tmp): Failed to open stream: No such file or directory in %s on line %d
100
101-- /%s/readfileVar8/readfileVar8Sub --
102The File Contents
103*** Done ***
104