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/* Prototype:  string tempnam ( string $dir, string $prefix );
11   Description: Create file with unique file name.
12*/
13
14/* Creating number of unique files by passing a file name as prefix */
15
16$file_path = dirname(__FILE__)."/tempnamVar1";
17mkdir($file_path);
18
19echo "*** Testing tempnam() in creation of unique files ***\n";
20for($i=1; $i<=10; $i++) {
21  echo "-- Iteration $i --\n";
22  $files[$i] = tempnam("$file_path", "tempnam_variation1.tmp");
23
24  if( file_exists($files[$i]) ) {
25
26    echo "File name is => ";
27    print($files[$i]);
28    echo "\n";
29
30    echo "File permissions are => ";
31    printf("%o", fileperms($files[$i]) );
32    echo "\n";
33    clearstatcache();
34
35    echo "File created in => ";
36    $file_dir = dirname($files[$i]);
37
38    if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) {
39       echo "temp dir\n";
40    }
41    else if (realpath($file_dir) == realpath($file_path) || realpath($file_dir."\\") == realpath($file_path)) {
42       echo "directory specified\n";
43    }
44    else {
45       echo "unknown location\n";
46    }
47    clearstatcache();
48  }
49  else {
50    print("- File is not created -");
51  }
52}
53for($i=1; $i<=10; $i++) {
54  unlink($files[$i]);
55}
56rmdir($file_path);
57
58
59echo "*** Done ***\n";
60?>
61--EXPECTF--
62*** Testing tempnam() in creation of unique files ***
63-- Iteration 1 --
64File name is => %s%et%s
65File permissions are => 100666
66File created in => directory specified
67-- Iteration 2 --
68File name is => %s%et%s
69File permissions are => 100666
70File created in => directory specified
71-- Iteration 3 --
72File name is => %s%et%s
73File permissions are => 100666
74File created in => directory specified
75-- Iteration 4 --
76File name is => %s%et%s
77File permissions are => 100666
78File created in => directory specified
79-- Iteration 5 --
80File name is => %s%et%s
81File permissions are => 100666
82File created in => directory specified
83-- Iteration 6 --
84File name is => %s%et%s
85File permissions are => 100666
86File created in => directory specified
87-- Iteration 7 --
88File name is => %s%et%s
89File permissions are => 100666
90File created in => directory specified
91-- Iteration 8 --
92File name is => %s%et%s
93File permissions are => 100666
94File created in => directory specified
95-- Iteration 9 --
96File name is => %s%et%s
97File permissions are => 100666
98File created in => directory specified
99-- Iteration 10 --
100File name is => %s%et%s
101File permissions are => 100666
102File created in => directory specified
103*** Done ***
104