1--TEST-- 2Test tempnam() function: usage variations - existing file 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/* Passing an existing file as $prefix for tempnam() fn */ 15 16$file_path = dirname(__FILE__); 17 18echo "*** Test tempnam() function: by passing an existing filename as prefix ***\n"; 19$dir_name = $file_path."/tempnam_variation5"; 20mkdir($dir_name); 21$h = fopen($dir_name."/tempnam_variation5.tmp", "w"); 22 23for($i=1; $i<=3; $i++) { 24 echo "-- Iteration $i --\n"; 25 $created_file = tempnam("$dir_name", "tempnam_variation5.tmp"); 26 27 if( file_exists($created_file) ) { 28 echo "File name is => "; 29 print($created_file); 30 echo "\n"; 31 } 32 else 33 print("File is not created"); 34 35 unlink($created_file); 36} 37fclose($h); 38unlink($dir_name."/tempnam_variation5.tmp"); 39rmdir($dir_name); 40 41echo "\n*** Done ***\n"; 42?> 43--EXPECTF-- 44*** Test tempnam() function: by passing an existing filename as prefix *** 45-- Iteration 1 -- 46File name is => %stempnam_variation5%etempnam_variation5.tmp%s 47-- Iteration 2 -- 48File name is => %stempnam_variation5%etempnam_variation5.tmp%s 49-- Iteration 3 -- 50File name is => %stempnam_variation5%etempnam_variation5.tmp%s 51 52*** Done *** 53