1--TEST--
2Test tempnam() function: usage variations - obscure prefixes
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 $prefix */
13
14echo "*** Testing tempnam() with obscure prefixes ***\n";
15$file_path = __DIR__."/tempnamVar3";
16mkdir($file_path);
17
18/* An array of prefixes */
19$names_arr = array(
20  /* Invalid args */
21  -1,
22  TRUE,
23  FALSE,
24  NULL,
25  "",
26  " ",
27  "\0",
28  array(),
29
30  /* prefix with path separator of a non existing directory*/
31  "/no/such/file/dir",
32  "php/php"
33
34);
35
36for( $i=0; $i<count($names_arr); $i++ ) {
37  echo "-- Iteration $i --\n";
38  try {
39    $file_name = tempnam("$file_path", $names_arr[$i]);
40  } catch (Error $e) {
41    echo $e->getMessage(), "\n";
42    continue;
43  }
44
45  /* creating the files in existing dir */
46  if( file_exists($file_name) ) {
47    echo "File name is => ";
48    print($file_name);
49    echo "\n";
50
51    echo "File permissions are => ";
52    printf("%o", fileperms($file_name) );
53    echo "\n";
54
55    echo "File created in => ";
56    $file_dir = dirname($file_name);
57
58    if ($file_dir == sys_get_temp_dir()) {
59       echo "temp dir\n";
60    }
61    else if ($file_dir == $file_path) {
62       echo "directory specified\n";
63    }
64    else {
65       echo "unknown location\n";
66    }
67
68  }
69  else {
70    echo "-- File is not created --\n";
71  }
72
73  unlink($file_name);
74}
75
76rmdir($file_path);
77?>
78--EXPECTF--
79*** Testing tempnam() with obscure prefixes ***
80-- Iteration 0 --
81File name is => %s/%s
82File permissions are => 100600
83File created in => directory specified
84-- Iteration 1 --
85File name is => %s/%s
86File permissions are => 100600
87File created in => directory specified
88-- Iteration 2 --
89File name is => %s/%s
90File permissions are => 100600
91File created in => directory specified
92-- Iteration 3 --
93File name is => %s/%s
94File permissions are => 100600
95File created in => directory specified
96-- Iteration 4 --
97File name is => %s/%s
98File permissions are => 100600
99File created in => directory specified
100-- Iteration 5 --
101File name is => %s/%s
102File permissions are => 100600
103File created in => directory specified
104-- Iteration 6 --
105tempnam(): Argument #2 ($prefix) must not contain any null bytes
106-- Iteration 7 --
107tempnam(): Argument #2 ($prefix) must be of type string, array given
108-- Iteration 8 --
109File name is => %s/dir%s
110File permissions are => 100600
111File created in => directory specified
112-- Iteration 9 --
113File name is => %s/php%s
114File permissions are => 100600
115File created in => directory specified
116