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 -- 68 69Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d 70File name is => %s%et%s 71File permissions are => 100666 72File created in => temp dir 73-- Iteration 1 -- 74 75Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d 76File name is => %s%et%s 77File permissions are => 100666 78File created in => temp dir 79-- Iteration 2 -- 80File name is => %s%et%s 81File permissions are => 100666 82File created in => temp dir 83-- Iteration 3 -- 84File name is => %s%et%s 85File permissions are => 100666 86File created in => temp dir 87-- Iteration 4 -- 88File name is => %s%et%s 89File permissions are => 100666 90File created in => temp dir 91-- Iteration 5 -- 92 93Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d 94File name is => %s%et%s 95File permissions are => 100666 96File created in => temp dir 97-- Iteration 6 -- 98 99Warning: tempnam() expects parameter 1 to be a valid path, string given in %stempnam_variation7-win32.php 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 7 -- 104 105Warning: tempnam() expects parameter 1 to be a valid path, array given in %s on line %d 106-- File is not created -- 107 108Warning: unlink(): %r(Invalid argument|No such file or directory)%r in %s on line %d 109-- Iteration 8 -- 110 111Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d 112File name is => %s%et%s 113File permissions are => 100666 114File created in => temp dir 115-- Iteration 9 -- 116 117Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation7-win32.php on line %d 118File name is => %s%et%s 119File permissions are => 100666 120File created in => temp dir 121 122*** Done *** 123