1--TEST--
2Test tempnam() function: usage variations - various absolute and relative paths
3--SKIPIF--
4<?php
5if(substr(PHP_OS, 0, 3) != "WIN")
6  die("skip Only valid for Windows");
7?>
8--FILE--
9<?php
10/* Prototype:  string tempnam ( string $dir, string $prefix );
11   Description: Create file with unique file name.
12*/
13
14/* Creating unique files in various dirs by passing relative paths to $dir arg */
15
16echo "*** Testing tempnam() with absolute and relative paths ***\n";
17$dir_name = __DIR__."/tempnam_variation2";
18mkdir($dir_name);
19$dir_path = $dir_name."/tempnam_variation2_sub";
20mkdir($dir_path);
21
22$old_dir_path = getcwd();
23chdir(__DIR__);
24
25$dir_paths = array(
26  // absolute paths
27  "$dir_path",
28  "$dir_path/",
29  "$dir_path/..",
30  "$dir_path//../",
31  "$dir_path/../.././tempnam_variation2",
32  "$dir_path/..///tempnam_variation2_sub//..//../tempnam_variation2",
33  "$dir_path/BADDIR",
34
35
36  // relative paths
37  ".",
38  "tempname_variation2",
39  "tempname_variation2/",
40  "tempnam_variation2/tempnam_variation2_sub",
41  "tempnam_variation2//tempnam_variation2_sub",
42  "./tempnam_variation2/../tempnam_variation2/tempnam_variation2_sub",
43  "BADDIR",
44);
45
46for($i = 0; $i<count($dir_paths); $i++) {
47  $j = $i+1;
48  echo "\n-- Iteration $j --\n";
49  $file_name = tempnam($dir_paths[$i], "tempnam_variation2.tmp");
50
51  if( file_exists($file_name) ){
52
53    echo "File name is => ";
54    print(realpath($file_name));
55    echo "\n";
56
57    echo "File permissions are => ";
58    printf("%o", fileperms($file_name) );
59    echo "\n";
60
61    echo "File created in => ";
62    $file_dir = dirname($file_name);
63    $dir_req = $dir_paths[$i];
64
65    if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) {
66       echo "temp dir\n";
67    }
68    else if (realpath($file_dir) == realpath($dir_req) || realpath($file_dir."\\") == realpath($dir_req)) {
69       echo "directory specified\n";
70    }
71    else {
72       echo "unknown location\n";
73    }
74
75
76  }
77  else {
78    echo "-- File is not created --";
79  }
80
81  unlink($file_name);
82}
83
84chdir($old_dir_path);
85rmdir($dir_path);
86rmdir($dir_name);
87
88echo "\n*** Done ***\n";
89?>
90--EXPECTF--
91*** Testing tempnam() with absolute and relative paths ***
92
93-- Iteration 1 --
94File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s
95File permissions are => 100666
96File created in => directory specified
97
98-- Iteration 2 --
99File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s
100File permissions are => 100666
101File created in => directory specified
102
103-- Iteration 3 --
104File name is => %s\tempnam_variation2\t%s
105File permissions are => 100666
106File created in => directory specified
107
108-- Iteration 4 --
109File name is => %s\tempnam_variation2\t%s
110File permissions are => 100666
111File created in => directory specified
112
113-- Iteration 5 --
114File name is => %s\tempnam_variation2\t%s
115File permissions are => 100666
116File created in => directory specified
117
118-- Iteration 6 --
119File name is => %s\tempnam_variation2\t%s
120File permissions are => 100666
121File created in => directory specified
122
123-- Iteration 7 --
124
125Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation2-win32.php on line %d
126File name is => %s\t%s
127File permissions are => 100666
128File created in => temp dir
129
130-- Iteration 8 --
131File name is => %s\t%s
132File permissions are => 100666
133File created in => directory specified
134
135-- Iteration 9 --
136
137Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation2-win32.php on line %d
138File name is => %s\t%s
139File permissions are => 100666
140File created in => temp dir
141
142-- Iteration 10 --
143
144Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation2-win32.php on line %d
145File name is => %s\t%s
146File permissions are => 100666
147File created in => temp dir
148
149-- Iteration 11 --
150File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s
151File permissions are => 100666
152File created in => directory specified
153
154-- Iteration 12 --
155File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s
156File permissions are => 100666
157File created in => directory specified
158
159-- Iteration 13 --
160File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s
161File permissions are => 100666
162File created in => directory specified
163
164-- Iteration 14 --
165
166Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation2-win32.php on line %d
167File name is => %s\t%s
168File permissions are => 100666
169File created in => temp dir
170
171*** Done ***
172