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