1--TEST--
2Test tempnam() function: usage variations - creating files
3--SKIPIF--
4<?php
5if(substr(PHP_OS, 0, 3) != "WIN")
6  die("skip Only valid for Windows");
7?>
8--FILE--
9<?php
10/* Creating number of unique files by passing a file name as prefix */
11
12$file_path = __DIR__."/tempnamVar1_私はガラスを食べられます";
13mkdir($file_path);
14
15echo "*** Testing tempnam() in creation of unique files ***\n";
16for($i=1; $i<=10; $i++) {
17  echo "-- Iteration $i --\n";
18  $files[$i] = tempnam("$file_path", "tempnam_variation1.tmp");
19
20  if( file_exists($files[$i]) ) {
21
22    echo "File name is => ";
23    print($files[$i]);
24    echo "\n";
25
26    echo "File permissions are => ";
27    printf("%o", fileperms($files[$i]) );
28    echo "\n";
29    clearstatcache();
30
31    echo "File created in => ";
32    $file_dir = dirname($files[$i]);
33
34    if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) {
35       echo "temp dir\n";
36    }
37    else if (realpath($file_dir) == realpath($file_path) || realpath($file_dir."\\") == realpath($file_path)) {
38       echo "directory specified\n";
39    }
40    else {
41       echo "unknown location\n";
42    }
43    clearstatcache();
44  }
45  else {
46    print("- File is not created -");
47  }
48}
49for($i=1; $i<=10; $i++) {
50  unlink($files[$i]);
51}
52rmdir($file_path);
53
54
55echo "*** Done ***\n";
56?>
57--EXPECTF--
58*** Testing tempnam() in creation of unique files ***
59-- Iteration 1 --
60File name is => %s%et%s
61File permissions are => 100666
62File created in => directory specified
63-- Iteration 2 --
64File name is => %s%et%s
65File permissions are => 100666
66File created in => directory specified
67-- Iteration 3 --
68File name is => %s%et%s
69File permissions are => 100666
70File created in => directory specified
71-- Iteration 4 --
72File name is => %s%et%s
73File permissions are => 100666
74File created in => directory specified
75-- Iteration 5 --
76File name is => %s%et%s
77File permissions are => 100666
78File created in => directory specified
79-- Iteration 6 --
80File name is => %s%et%s
81File permissions are => 100666
82File created in => directory specified
83-- Iteration 7 --
84File name is => %s%et%s
85File permissions are => 100666
86File created in => directory specified
87-- Iteration 8 --
88File name is => %s%et%s
89File permissions are => 100666
90File created in => directory specified
91-- Iteration 9 --
92File name is => %s%et%s
93File permissions are => 100666
94File created in => directory specified
95-- Iteration 10 --
96File name is => %s%et%s
97File permissions are => 100666
98File created in => directory specified
99*** Done ***
100