1--TEST-- 2Test tempnam() function: usage variations - Using previous unique filename 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/* Trying to create unique files by passing previously created unique file name as prefix */ 15 16$file_path = dirname(__FILE__); 17 18echo "\n*** Test tempnam(): by passing previously created filenames ***\n"; 19$file_name = "tempnam_variation6.tmp"; 20for($i=1; $i<=3; $i++) { 21 echo "-- Iteration $i --\n"; 22 $file_name = tempnam("$file_path", $file_name); 23 24 if( file_exists($file_name) ) { 25 echo "File name is => "; 26 print($file_name); 27 echo "\n"; 28 29 echo "File created in => "; 30 $file_dir = dirname($file_name); 31 32 if ($file_dir == sys_get_temp_dir()) { 33 echo "temp dir\n"; 34 } 35 else if ($file_dir == $file_path) { 36 echo "directory specified\n"; 37 } 38 else { 39 echo "unknown location\n"; 40 } 41 } 42 43 unlink($file_name); 44} 45 46echo "\n*** Done ***\n"; 47?> 48--EXPECTF-- 49*** Test tempnam(): by passing previously created filenames *** 50-- Iteration 1 -- 51File name is => %s%etempnam_variation6.tmp%s 52File created in => directory specified 53-- Iteration 2 -- 54File name is => %s%etempnam_variation6.tmp%s 55File created in => directory specified 56-- Iteration 3 -- 57File name is => %s%etempnam_variation6.tmp%s 58File created in => directory specified 59 60*** Done *** 61