1--TEST--
2Test tempnam() function: usage variations - Using previous unique filename
3--CREDITS--
4Dave Kelsey <d_kelsey@uk.ibm.com>
5--SKIPIF--
6<?php
7if(substr(PHP_OS, 0, 3) != "WIN")
8  die("skip Windows Only");
9?>
10--FILE--
11<?php
12/* Prototype:  string tempnam ( string $dir, string $prefix );
13   Description: Create file with unique file name.
14*/
15
16/* Trying to create unique files by passing previously created unique file name as prefix */
17
18$file_path = dirname(__FILE__);
19
20echo "\n*** Test tempnam(): by passing previously created filenames ***\n";
21$file_name = "tempnam_variation6.tmp";
22for($i=1; $i<=3; $i++) {
23  echo "-- Iteration $i --\n";
24  $file_name = tempnam("$file_path", $file_name);
25
26  if( file_exists($file_name) ) {
27    echo "File name is => ";
28    print($file_name);
29    echo "\n";
30
31    echo "File created in => ";
32    $file_dir = dirname($file_name);
33
34    if ($file_dir == sys_get_temp_dir()) {
35       echo "temp dir\n";
36    }
37    else if ($file_dir == $file_path) {
38       echo "directory specified\n";
39    }
40    else {
41       echo "unknown location\n";
42    }
43 }
44
45  unlink($file_name);
46}
47
48echo "\n*** Done ***\n";
49?>
50--EXPECTF--
51*** Test tempnam(): by passing previously created filenames ***
52-- Iteration 1 --
53File name is => %s%et%s
54File created in => directory specified
55-- Iteration 2 --
56File name is => %s%et%s
57File created in => directory specified
58-- Iteration 3 --
59File name is => %s%et%s
60File created in => directory specified
61
62*** Done ***
63