1--TEST--
2Test tempnam() function: usage variations - creating files
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/* 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 inode is => ";
32    print_r( fileinode($files[$i]) ); //checking inodes
33    echo "\n";
34
35    echo "File created in => ";
36    $file_dir = dirname($files[$i]);
37
38    if ($file_dir == sys_get_temp_dir()) {
39       echo "temp dir\n";
40    }
41    else if ($file_dir == $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}
56
57rmdir($file_path);
58echo "*** Done ***\n";
59?>
60--EXPECTF--
61*** Testing tempnam() in creation of unique files ***
62-- Iteration 1 --
63File name is => %s%etempnam_variation1.tmp%s
64File permissions are => 100600
65File inode is => %i
66File created in => directory specified
67-- Iteration 2 --
68File name is => %s%etempnam_variation1.tmp%s
69File permissions are => 100600
70File inode is => %i
71File created in => directory specified
72-- Iteration 3 --
73File name is => %s%etempnam_variation1.tmp%s
74File permissions are => 100600
75File inode is => %i
76File created in => directory specified
77-- Iteration 4 --
78File name is => %s%etempnam_variation1.tmp%s
79File permissions are => 100600
80File inode is => %i
81File created in => directory specified
82-- Iteration 5 --
83File name is => %s%etempnam_variation1.tmp%s
84File permissions are => 100600
85File inode is => %i
86File created in => directory specified
87-- Iteration 6 --
88File name is => %s%etempnam_variation1.tmp%s
89File permissions are => 100600
90File inode is => %i
91File created in => directory specified
92-- Iteration 7 --
93File name is => %s%etempnam_variation1.tmp%s
94File permissions are => 100600
95File inode is => %i
96File created in => directory specified
97-- Iteration 8 --
98File name is => %s%etempnam_variation1.tmp%s
99File permissions are => 100600
100File inode is => %i
101File created in => directory specified
102-- Iteration 9 --
103File name is => %s%etempnam_variation1.tmp%s
104File permissions are => 100600
105File inode is => %i
106File created in => directory specified
107-- Iteration 10 --
108File name is => %s%etempnam_variation1.tmp%s
109File permissions are => 100600
110File inode is => %i
111File created in => directory specified
112*** Done ***
113