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 --
73File name is => %s%etempnam_variation3.tmp%s
74File permissions are => 100600
75File created in => temp dir
76-- Iteration 1 --
77File name is => %s%etempnam_variation3.tmp%s
78File permissions are => 100600
79File created in => temp dir
80-- Iteration 2 --
81File name is => %s%etempnam_variation3.tmp%s
82File permissions are => 100600
83File created in => temp dir
84-- Iteration 3 --
85File name is => %s%etempnam_variation3.tmp%s
86File permissions are => 100600
87File created in => temp dir
88-- Iteration 4 --
89File name is => %s%etempnam_variation3.tmp%s
90File permissions are => 100600
91File created in => temp dir
92-- Iteration 5 --
93File name is => %s%etempnam_variation3.tmp%s
94File permissions are => 100600
95File created in => temp dir
96-- Iteration 6 --
97
98Warning: tempnam() expects parameter 1 to be a valid path, string given in %s on line %d
99-- File is not created --
100
101Warning: unlink(): %s in %s on line %d
102-- Iteration 7 --
103
104Warning: tempnam() expects parameter 1 to be a valid path, array given in %s on line %d
105-- File is not created --
106
107Warning: unlink(): %s in %s on line %d
108-- Iteration 8 --
109File name is => %s/tempnam_variation3.tmp%s
110File permissions are => 100600
111File created in => temp dir
112-- Iteration 9 --
113File name is => %s/tempnam_variation3.tmp%s
114File permissions are => 100600
115File created in => temp dir
116
117*** Done ***
118
119