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/* 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 inode is => "; 36 print_r( fileinode($files[$i]) ); //checking inodes 37 echo "\n"; 38 39 echo "File created in => "; 40 $file_dir = dirname($files[$i]); 41 42 if ($file_dir == sys_get_temp_dir()) { 43 echo "temp dir\n"; 44 } 45 else if ($file_dir == $file_path) { 46 echo "directory specified\n"; 47 } 48 else { 49 echo "unknown location\n"; 50 } 51 clearstatcache(); 52 } 53 else { 54 print("- File is not created -"); 55 } 56} 57for($i=1; $i<=10; $i++) { 58 unlink($files[$i]); 59} 60 61rmdir($file_path); 62echo "*** Done ***\n"; 63?> 64--EXPECTF-- 65*** Testing tempnam() in creation of unique files *** 66-- Iteration 1 -- 67File name is => %s%etempnam_variation1.tmp%s 68File permissions are => 100600 69File inode is => %d 70File created in => directory specified 71-- Iteration 2 -- 72File name is => %s%etempnam_variation1.tmp%s 73File permissions are => 100600 74File inode is => %d 75File created in => directory specified 76-- Iteration 3 -- 77File name is => %s%etempnam_variation1.tmp%s 78File permissions are => 100600 79File inode is => %d 80File created in => directory specified 81-- Iteration 4 -- 82File name is => %s%etempnam_variation1.tmp%s 83File permissions are => 100600 84File inode is => %d 85File created in => directory specified 86-- Iteration 5 -- 87File name is => %s%etempnam_variation1.tmp%s 88File permissions are => 100600 89File inode is => %d 90File created in => directory specified 91-- Iteration 6 -- 92File name is => %s%etempnam_variation1.tmp%s 93File permissions are => 100600 94File inode is => %d 95File created in => directory specified 96-- Iteration 7 -- 97File name is => %s%etempnam_variation1.tmp%s 98File permissions are => 100600 99File inode is => %d 100File created in => directory specified 101-- Iteration 8 -- 102File name is => %s%etempnam_variation1.tmp%s 103File permissions are => 100600 104File inode is => %d 105File created in => directory specified 106-- Iteration 9 -- 107File name is => %s%etempnam_variation1.tmp%s 108File permissions are => 100600 109File inode is => %d 110File created in => directory specified 111-- Iteration 10 -- 112File name is => %s%etempnam_variation1.tmp%s 113File permissions are => 100600 114File inode is => %d 115File created in => directory specified 116*** Done *** 117