1--TEST-- 2Test tempnam() function: usage variations - obscure prefixes 3--SKIPIF-- 4<?php 5if(substr(PHP_OS, 0, 3) == "WIN") 6 die("skip Do not run on Windows"); 7?> 8--CONFLICTS-- 9obscure_filename 10--FILE-- 11<?php 12/* Prototype: string tempnam ( string $dir, string $prefix ); 13 Description: Create file with unique file name. 14*/ 15 16/* Passing invalid/non-existing args for $prefix */ 17 18echo "*** Testing tempnam() with obscure prefixes ***\n"; 19$file_path = __DIR__."/tempnamVar3"; 20mkdir($file_path); 21 22/* An array of prefixes */ 23$names_arr = array( 24 /* Invalid args */ 25 -1, 26 TRUE, 27 FALSE, 28 NULL, 29 "", 30 " ", 31 "\0", 32 array(), 33 34 /* prefix with path separator of a non existing directory*/ 35 "/no/such/file/dir", 36 "php/php" 37 38); 39 40for( $i=0; $i<count($names_arr); $i++ ) { 41 echo "-- Iteration $i --\n"; 42 $file_name = tempnam("$file_path", $names_arr[$i]); 43 44 /* creating the files in existing dir */ 45 if( file_exists($file_name) ) { 46 echo "File name is => "; 47 print($file_name); 48 echo "\n"; 49 50 echo "File permissions are => "; 51 printf("%o", fileperms($file_name) ); 52 echo "\n"; 53 54 echo "File created in => "; 55 $file_dir = dirname($file_name); 56 57 if ($file_dir == sys_get_temp_dir()) { 58 echo "temp dir\n"; 59 } 60 else if ($file_dir == $file_path) { 61 echo "directory specified\n"; 62 } 63 else { 64 echo "unknown location\n"; 65 } 66 67 } 68 else { 69 echo "-- File is not created --\n"; 70 } 71 72 unlink($file_name); 73} 74 75rmdir($file_path); 76?> 77--EXPECTF-- 78*** Testing tempnam() with obscure prefixes *** 79-- Iteration 0 -- 80File name is => %s/%s 81File permissions are => 100600 82File created in => directory specified 83-- Iteration 1 -- 84File name is => %s/%s 85File permissions are => 100600 86File created in => directory specified 87-- Iteration 2 -- 88File name is => %s/%s 89File permissions are => 100600 90File created in => directory specified 91-- Iteration 3 -- 92File name is => %s/%s 93File permissions are => 100600 94File created in => directory specified 95-- Iteration 4 -- 96File name is => %s/%s 97File permissions are => 100600 98File created in => directory specified 99-- Iteration 5 -- 100File name is => %s/%s 101File permissions are => 100600 102File created in => directory specified 103-- Iteration 6 -- 104 105Warning: tempnam() expects parameter 2 to be a valid path, string given in %s on line %d 106-- File is not created -- 107 108Warning: unlink(): %s in %s on line %d 109-- Iteration 7 -- 110 111Warning: tempnam() expects parameter 2 to be a valid path, array given in %s on line %d 112-- File is not created -- 113 114Warning: unlink(): %s in %s on line %d 115-- Iteration 8 -- 116File name is => %s/dir%s 117File permissions are => 100600 118File created in => directory specified 119-- Iteration 9 -- 120File name is => %s/php%s 121File permissions are => 100600 122File created in => directory specified 123