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