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 = dirname(__FILE__)."\\tempnam_variation2";
20mkdir($dir_name);
21$dir_path = $dir_name."/tempnam_variation2_sub";
22mkdir($dir_path);
23
24$old_dir_path = getcwd();
25chdir(dirname(__FILE__));
26
27$dir_paths = array(
28  // absolute paths
29  "$dir_path\\",
30  "$dir_path\\..",
31  "$dir_path\\\\..\\",
32  "$dir_path\\..\\..\\.\\tempnam_variation2",
33  "$dir_path\\..\\\\\\tempnam_variation2_sub\\\\..\\\\..\\tempnam_variation2",
34  "$dir_path\\BADDIR",
35
36
37  // relative paths
38  "tempname_variation2\\",
39  "tempnam_variation2\\tempnam_variation2_sub",
40  "tempnam_variation2\\\\tempnam_variation2_sub",
41  ".\\tempnam_variation2\\..\\tempnam_variation2\\tempnam_variation2_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_variation2.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_variation2\tempnam_variation2_sub\t%s
94File permissions are => 100666
95File created in => directory specified
96
97-- Iteration 2 --
98File name is => %s\tempnam_variation2\t%s
99File permissions are => 100666
100File created in => directory specified
101
102-- Iteration 3 --
103File name is => %s\tempnam_variation2\t%s
104File permissions are => 100666
105File created in => directory specified
106
107-- Iteration 4 --
108File name is => %s\tempnam_variation2\t%s
109File permissions are => 100666
110File created in => directory specified
111
112-- Iteration 5 --
113File name is => %s\tempnam_variation2\t%s
114File permissions are => 100666
115File created in => directory specified
116
117-- Iteration 6 --
118File name is => %s\t%s
119File permissions are => 100666
120File created in => temp dir
121
122-- Iteration 7 --
123File name is => %s\t%s
124File permissions are => 100666
125File created in => temp dir
126
127-- Iteration 8 --
128File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s
129File permissions are => 100666
130File created in => directory specified
131
132-- Iteration 9 --
133File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s
134File permissions are => 100666
135File created in => directory specified
136
137-- Iteration 10 --
138File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s
139File permissions are => 100666
140File created in => directory specified
141
142-- Iteration 11 --
143File name is => %s\t%s
144File permissions are => 100666
145File created in => temp dir
146
147*** Done ***
148