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