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