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--FILE--
9<?php
10/* Prototype:  string tempnam ( string $dir, string $prefix );
11   Description: Create file with unique file name.
12*/
13
14/* Passing invalid/non-existing args for $dir,
15     hence the unique files will be created in temporary dir */
16
17echo "*** Testing tempnam() with invalid/non-existing directory names ***\n";
18/* An array of names, which will be passed as a dir name */
19$names_arr = array(
20  /* Invalid args */
21  -1,
22  TRUE,
23  FALSE,
24  NULL,
25  "",
26  " ",
27  "\0",
28  array(),
29
30  /* Non-existing dirs */
31  "/no/such/file/dir",
32  "php"
33
34);
35
36for( $i=0; $i<count($names_arr); $i++ ) {
37  echo "-- Iteration $i --\n";
38  $file_name = tempnam($names_arr[$i], "tempnam_variation3.tmp");
39
40  if( file_exists($file_name) ){
41
42    echo "File name is => ";
43    print($file_name);
44    echo "\n";
45
46    echo "File permissions are => ";
47    printf("%o", fileperms($file_name) );
48    echo "\n";
49
50    echo "File created in => ";
51    $file_dir = dirname($file_name);
52
53    if (realpath($file_dir) == realpath(sys_get_temp_dir())) {
54       echo "temp dir\n";
55    }
56    else {
57       echo "unknown location\n";
58    }
59
60  }
61  else {
62    echo "-- File is not created --\n";
63  }
64
65  unlink($file_name);
66}
67
68echo "\n*** Done ***\n";
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 --
93File name is => %s%etempnam_variation3.tmp%s
94File permissions are => 100600
95File created in => temp dir
96-- Iteration 5 --
97
98Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7.php on line %d
99File name is => %s%etempnam_variation3.tmp%s
100File permissions are => 100600
101File created in => temp dir
102-- Iteration 6 --
103
104Warning: tempnam() expects parameter 1 to be a valid path, string given in %s on line %d
105-- File is not created --
106
107Warning: unlink(): %s in %s on line %d
108-- Iteration 7 --
109
110Warning: tempnam() expects parameter 1 to be a valid path, array given in %s on line %d
111-- File is not created --
112
113Warning: unlink(): %s in %s on line %d
114-- Iteration 8 --
115
116Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7.php on line %d
117File name is => %s/tempnam_variation3.tmp%s
118File permissions are => 100600
119File created in => temp dir
120-- Iteration 9 --
121
122Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7.php on line %d
123File name is => %s/tempnam_variation3.tmp%s
124File permissions are => 100600
125File created in => temp dir
126
127*** Done ***
128