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    NULL,
23    "",
24    " ",
25    "\0",
26    array(),
27
28    /* Non-existing dirs */
29    "/no/such/file/dir",
30    "php"
31);
32
33for( $i=0; $i<count($names_arr); $i++ ) {
34    echo "-- Iteration $i --\n";
35    try {
36        $file_name = tempnam($names_arr[$i], "tempnam_variation3.tmp");
37    } catch (Error $e) {
38        echo $e->getMessage(), "\n";
39        continue;
40    }
41
42    if( file_exists($file_name) ){
43
44        echo "File name is => ";
45        print($file_name);
46        echo "\n";
47
48        echo "File permissions are => ";
49        printf("%o", fileperms($file_name) );
50        echo "\n";
51
52        echo "File created in => ";
53        $file_dir = dirname($file_name);
54        if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) {
55            echo "temp dir\n";
56        } else {
57            echo "unknown location\n";
58        }
59    } else {
60        echo "-- File is not created --\n";
61    }
62
63    unlink($file_name);
64}
65?>
66--EXPECTF--
67*** Testing tempnam() with invalid/non-existing directory names ***
68-- Iteration 0 --
69
70Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
71File name is => %s%et%s
72File permissions are => 100666
73File created in => temp dir
74-- Iteration 1 --
75
76Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
77File name is => %s%et%s
78File permissions are => 100666
79File created in => temp dir
80-- Iteration 2 --
81File name is => %s%et%s
82File permissions are => 100666
83File created in => temp dir
84-- Iteration 3 --
85File name is => %s%et%s
86File permissions are => 100666
87File created in => temp dir
88-- Iteration 4 --
89File name is => %s%et%s
90File permissions are => 100666
91File created in => temp dir
92-- Iteration 5 --
93
94Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
95File name is => %s%et%s
96File permissions are => 100666
97File created in => temp dir
98-- Iteration 6 --
99tempnam(): Argument #1 ($directory) must not contain any null bytes
100-- Iteration 7 --
101tempnam(): Argument #1 ($directory) must be of type string, array given
102-- Iteration 8 --
103
104Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
105File name is => %s%et%s
106File permissions are => 100666
107File created in => temp dir
108-- Iteration 9 --
109
110Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d
111File name is => %s%et%s
112File permissions are => 100666
113File created in => temp dir
114