1--TEST-- 2Test tempnam() function: usage variations - invalid/non-existing dir 3--SKIPIF-- 4<?php 5if(substr(PHP_OS, 0, 3) != "WIN") 6 die("skip Only 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 invalid/non-existing args for $dir, 15 hence the unique files will be created in temporary dir */ 16 17echo "*** Testing tempnam() with invalid/non-existing directory names ***\n"; 18/* An array of names, which will be passed as a dir name */ 19$names_arr = array( 20 /* Invalid args */ 21 -1, 22 TRUE, 23 FALSE, 24 NULL, 25 "", 26 " ", 27 "\0", 28 array(), 29 30 /* Non-existing dirs */ 31 "/no/such/file/dir", 32 "php" 33); 34 35for( $i=0; $i<count($names_arr); $i++ ) { 36 echo "-- Iteration $i --\n"; 37 $file_name = tempnam($names_arr[$i], "tempnam_variation3.tmp"); 38 39 if( file_exists($file_name) ){ 40 41 echo "File name is => "; 42 print($file_name); 43 echo "\n"; 44 45 echo "File permissions are => "; 46 printf("%o", fileperms($file_name) ); 47 echo "\n"; 48 49 echo "File created in => "; 50 $file_dir = dirname($file_name); 51 if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) { 52 echo "temp dir\n"; 53 } else { 54 echo "unknown location\n"; 55 } 56 } else { 57 echo "-- File is not created --\n"; 58 } 59 60 unlink($file_name); 61} 62 63echo "\n*** Done ***\n"; 64?> 65--EXPECTF-- 66*** Testing tempnam() with invalid/non-existing directory names *** 67-- Iteration 0 -- 68File name is => %s%et%s 69File permissions are => 100666 70File created in => temp dir 71-- Iteration 1 -- 72File name is => %s%et%s 73File permissions are => 100666 74File created in => temp dir 75-- Iteration 2 -- 76File name is => %s%et%s 77File permissions are => 100666 78File created in => temp dir 79-- Iteration 3 -- 80File name is => %s%et%s 81File permissions are => 100666 82File created in => temp dir 83-- Iteration 4 -- 84File name is => %s%et%s 85File permissions are => 100666 86File created in => temp dir 87-- Iteration 5 -- 88File name is => %s%et%s 89File permissions are => 100666 90File created in => temp dir 91-- Iteration 6 -- 92 93Warning: tempnam() expects parameter 1 to be a valid path, string given in %stempnam_variation7-win32.php on line %d 94-- File is not created -- 95 96Warning: unlink(): %r(Invalid argument|No such file or directory)%r in %s on line %d 97-- Iteration 7 -- 98 99Warning: tempnam() expects parameter 1 to be a valid path, array given in %s on line %d 100-- File is not created -- 101 102Warning: unlink(): %r(Invalid argument|No such file or directory)%r in %s on line %d 103-- Iteration 8 -- 104File name is => %s%et%s 105File permissions are => 100666 106File created in => temp dir 107-- Iteration 9 -- 108File name is => %s%et%s 109File permissions are => 100666 110File created in => temp dir 111 112*** Done *** 113 114