1--TEST--
2Test tempnam() function: usage variations - invalid/non-existing dir
3--SKIPIF--
4<?php
5if(substr(PHP_OS, 0, 3) != "WIN")
6  die("skip Only run on Windows");
7?>
8--CONFLICTS--
9obscure_filename
10--FILE--
11<?php
12/* Prototype:  string tempnam ( string $dir, string $prefix );
13   Description: Create file with unique file name.
14*/
15
16/* Passing invalid/non-existing args for $dir,
17     hence the unique files will be created in temporary dir */
18
19echo "*** Testing tempnam() with invalid/non-existing directory names ***\n";
20/* An array of names, which will be passed as a dir name */
21$names_arr = array(
22	/* Invalid args */
23	-1,
24	TRUE,
25	FALSE,
26	NULL,
27	"",
28	" ",
29	"\0",
30	array(),
31
32	/* Non-existing dirs */
33	"/no/such/file/dir",
34	"php"
35);
36
37for( $i=0; $i<count($names_arr); $i++ ) {
38	echo "-- Iteration $i --\n";
39	$file_name = tempnam($names_arr[$i], "tempnam_variation3.tmp");
40
41	if( file_exists($file_name) ){
42
43		echo "File name is => ";
44		print($file_name);
45		echo "\n";
46
47		echo "File permissions are => ";
48		printf("%o", fileperms($file_name) );
49		echo "\n";
50
51		echo "File created in => ";
52		$file_dir = dirname($file_name);
53		if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) {
54			echo "temp dir\n";
55		} else {
56			echo "unknown location\n";
57		}
58	} else {
59		echo "-- File is not created --\n";
60	}
61
62	unlink($file_name);
63}
64?>
65--EXPECTF--
66*** Testing tempnam() with invalid/non-existing directory names ***
67-- Iteration 0 --
68
69Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
70File name is => %s%et%s
71File permissions are => 100666
72File created in => temp dir
73-- Iteration 1 --
74
75Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
76File name is => %s%et%s
77File permissions are => 100666
78File created in => temp dir
79-- Iteration 2 --
80File name is => %s%et%s
81File permissions are => 100666
82File created in => temp dir
83-- Iteration 3 --
84File name is => %s%et%s
85File permissions are => 100666
86File created in => temp dir
87-- Iteration 4 --
88File name is => %s%et%s
89File permissions are => 100666
90File created in => temp dir
91-- Iteration 5 --
92
93Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
94File name is => %s%et%s
95File permissions are => 100666
96File created in => temp dir
97-- Iteration 6 --
98
99Warning: tempnam() expects parameter 1 to be a valid path, string given in %stempnam_variation7-win32.php on line %d
100-- File is not created --
101
102Warning: unlink(): %r(Invalid argument|No such file or directory)%r in %s on line %d
103-- Iteration 7 --
104
105Warning: tempnam() expects parameter 1 to be a valid path, array given in %s on line %d
106-- File is not created --
107
108Warning: unlink(): %r(Invalid argument|No such file or directory)%r in %s on line %d
109-- Iteration 8 --
110
111Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
112File name is => %s%et%s
113File permissions are => 100666
114File created in => temp dir
115-- Iteration 9 --
116
117Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
118File name is => %s%et%s
119File permissions are => 100666
120File created in => temp dir
121