1--TEST-- 2Test tempnam() function: usage variations - obscure prefixes 3--SKIPIF-- 4<?php 5if(substr(PHP_OS, 0, 3) != "WIN") 6 die("skip run only 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 $prefix */ 15 16echo "*** Testing tempnam() with obscure prefixes ***\n"; 17$file_path = dirname(__FILE__)."/tempnamVar3"; 18if (!mkdir($file_path)) { 19 echo "Failed, cannot create temp dir $filepath\n"; 20 exit(1); 21} 22 23$file_path = realpath($file_path); 24 25/* An array of prefixes */ 26$names_arr = array( 27 /* Valid args (casting)*/ 28 -1, 29 TRUE, 30 FALSE, 31 NULL, 32 "", 33 " ", 34 "\0", 35 /* Invalid args */ 36 array(), 37 38 /* Valid args*/ 39 /* prefix with path separator of a non existing directory*/ 40 "/no/such/file/dir", 41 "php/php" 42); 43 44$res_arr = array( 45 /* Invalid args */ 46 true, 47 true, 48 true, 49 true, 50 true, 51 true, 52 true, 53 false, 54 55 /* prefix with path separator of a non existing directory*/ 56 true, 57 true 58); 59 60for( $i=0; $i<count($names_arr); $i++ ) { 61 echo "-- Iteration $i --\n"; 62 $file_name = tempnam($file_path, $names_arr[$i]); 63 64 /* creating the files in existing dir */ 65 if (file_exists($file_name) && !$res_arr[$i]) { 66 echo "Failed\n"; 67 } 68 if ($res_arr[$i]) { 69 $file_dir = dirname($file_name); 70 if (realpath($file_dir) == $file_path || realpath($file_dir . "\\") == $file_path) { 71 echo "OK\n"; 72 } else { 73 echo "Failed, not created in the correct directory " . realpath($file_dir) . ' vs ' . $file_path ."\n"; 74 } 75 76 if (!is_writable($file_name)) { 77 printf("%o\n", fileperms($file_name) ); 78 79 } 80 } else { 81 echo "OK\n"; 82 } 83 @unlink($file_name); 84} 85 86rmdir($file_path); 87echo "\n*** Done. ***\n"; 88?> 89--EXPECTF-- 90*** Testing tempnam() with obscure prefixes *** 91-- Iteration 0 -- 92OK 93-- Iteration 1 -- 94OK 95-- Iteration 2 -- 96OK 97-- Iteration 3 -- 98OK 99-- Iteration 4 -- 100OK 101-- Iteration 5 -- 102 103Notice: tempnam(): file created in the system's temporary directory in %stempnam_variation3-win32.php on line %d 104Failed, not created in the correct directory %s vs %s 1050 106-- Iteration 6 -- 107 108Warning: tempnam() expects parameter 2 to be a valid path, string given in %stempnam_variation3-win32.php on line 54 109Failed, not created in the correct directory %s vs %sext\standard\tests\file\tempnamVar3 1100 111-- Iteration 7 -- 112 113Warning: tempnam() expects parameter 2 to be a valid path, array given in %s\ext\standard\tests\file\tempnam_variation3-win32.php on line %d 114OK 115-- Iteration 8 -- 116OK 117-- Iteration 9 -- 118OK 119 120*** Done. *** 121