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 Do not 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);
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
55    if (realpath($file_dir) == realpath(sys_get_temp_dir())) {
56       echo "temp dir\n";
57    }
58    else {
59       echo "unknown location\n";
60    }
61
62  }
63  else {
64    echo "-- File is not created --\n";
65  }
66
67  unlink($file_name);
68}
69?>
70--EXPECTF--
71*** Testing tempnam() with invalid/non-existing directory names ***
72-- Iteration 0 --
73
74Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7.php on line %d
75File name is => %s%etempnam_variation3.tmp%s
76File permissions are => 100600
77File created in => temp dir
78-- Iteration 1 --
79
80Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7.php on line %d
81File name is => %s%etempnam_variation3.tmp%s
82File permissions are => 100600
83File created in => temp dir
84-- Iteration 2 --
85File name is => %s%etempnam_variation3.tmp%s
86File permissions are => 100600
87File created in => temp dir
88-- Iteration 3 --
89File name is => %s%etempnam_variation3.tmp%s
90File permissions are => 100600
91File created in => temp dir
92-- Iteration 4 --
93
94Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7.php on line %d
95File name is => %s%etempnam_variation3.tmp%s
96File permissions are => 100600
97File created in => temp dir
98-- Iteration 5 --
99tempnam(): Argument #1 ($directory) must not contain any null bytes
100-- Iteration 6 --
101tempnam(): Argument #1 ($directory) must be of type string, array given
102-- Iteration 7 --
103
104Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7.php on line %d
105File name is => %s/tempnam_variation3.tmp%s
106File permissions are => 100600
107File created in => temp dir
108-- Iteration 8 --
109
110Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7.php on line %d
111File name is => %s/tempnam_variation3.tmp%s
112File permissions are => 100600
113File created in => temp dir
114