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/* Passing invalid/non-existing args for $dir,
13     hence the unique files will be created in temporary dir */
14
15echo "*** Testing tempnam() with invalid/non-existing directory names ***\n";
16/* An array of names, which will be passed as a dir name */
17$names_arr = array(
18    /* Invalid args */
19    -1,
20    TRUE,
21    FALSE,
22    "",
23    " ",
24    "\0",
25    array(),
26
27    /* Non-existing dirs */
28    "/no/such/file/dir",
29    "php"
30);
31
32for( $i=0; $i<count($names_arr); $i++ ) {
33    echo "-- Iteration $i --\n";
34    try {
35        $file_name = tempnam($names_arr[$i], "tempnam_variation3.tmp");
36    } catch (Error $e) {
37        echo $e->getMessage(), "\n";
38        continue;
39    }
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 --
88
89Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
90File name is => %s%et%s
91File permissions are => 100666
92File created in => temp dir
93-- Iteration 5 --
94tempnam(): Argument #1 ($directory) must not contain any null bytes
95-- Iteration 6 --
96tempnam(): Argument #1 ($directory) must be of type string, array given
97-- Iteration 7 --
98
99Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
100File name is => %s%et%s
101File permissions are => 100666
102File created in => temp dir
103-- Iteration 8 --
104
105Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
106File name is => %s%et%s
107File permissions are => 100666
108File created in => temp dir
109