1--TEST-- 2Test tempnam() function: usage variations - various absolute and relative paths 3--SKIPIF-- 4<?php 5if(substr(PHP_OS, 0, 3) != "WIN") 6 die("skip Only valid for 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 unique files in various dirs by passing relative paths to $dir arg */ 15 16echo "*** Testing tempnam() with absolute and relative paths ***\n"; 17$dir_name = dirname(__FILE__)."/tempnam_variation2"; 18mkdir($dir_name); 19$dir_path = $dir_name."/tempnam_variation2_sub"; 20mkdir($dir_path); 21 22$old_dir_path = getcwd(); 23chdir(dirname(__FILE__)); 24 25$dir_paths = array( 26 // absolute paths 27 "$dir_path", 28 "$dir_path/", 29 "$dir_path/..", 30 "$dir_path//../", 31 "$dir_path/../.././tempnam_variation2", 32 "$dir_path/..///tempnam_variation2_sub//..//../tempnam_variation2", 33 "$dir_path/BADDIR", 34 35 36 // relative paths 37 ".", 38 "tempname_variation2", 39 "tempname_variation2/", 40 "tempnam_variation2/tempnam_variation2_sub", 41 "tempnam_variation2//tempnam_variation2_sub", 42 "./tempnam_variation2/../tempnam_variation2/tempnam_variation2_sub", 43 "BADDIR", 44); 45 46for($i = 0; $i<count($dir_paths); $i++) { 47 $j = $i+1; 48 echo "\n-- Iteration $j --\n"; 49 $file_name = tempnam($dir_paths[$i], "tempnam_variation2.tmp"); 50 51 if( file_exists($file_name) ){ 52 53 echo "File name is => "; 54 print(realpath($file_name)); 55 echo "\n"; 56 57 echo "File permissions are => "; 58 printf("%o", fileperms($file_name) ); 59 echo "\n"; 60 61 echo "File created in => "; 62 $file_dir = dirname($file_name); 63 $dir_req = $dir_paths[$i]; 64 65 if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) { 66 echo "temp dir\n"; 67 } 68 else if (realpath($file_dir) == realpath($dir_req) || realpath($file_dir."\\") == realpath($dir_req)) { 69 echo "directory specified\n"; 70 } 71 else { 72 echo "unknown location\n"; 73 } 74 75 76 } 77 else { 78 echo "-- File is not created --"; 79 } 80 81 unlink($file_name); 82} 83 84chdir($old_dir_path); 85rmdir($dir_path); 86rmdir($dir_name); 87 88echo "\n*** Done ***\n"; 89?> 90--EXPECTF-- 91*** Testing tempnam() with absolute and relative paths *** 92 93-- Iteration 1 -- 94File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s 95File permissions are => 100666 96File created in => directory specified 97 98-- Iteration 2 -- 99File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s 100File permissions are => 100666 101File created in => directory specified 102 103-- Iteration 3 -- 104File name is => %s\tempnam_variation2\t%s 105File permissions are => 100666 106File created in => directory specified 107 108-- Iteration 4 -- 109File name is => %s\tempnam_variation2\t%s 110File permissions are => 100666 111File created in => directory specified 112 113-- Iteration 5 -- 114File name is => %s\tempnam_variation2\t%s 115File permissions are => 100666 116File created in => directory specified 117 118-- Iteration 6 -- 119File name is => %s\tempnam_variation2\t%s 120File permissions are => 100666 121File created in => directory specified 122 123-- Iteration 7 -- 124File name is => %s\t%s 125File permissions are => 100666 126File created in => temp dir 127 128-- Iteration 8 -- 129File name is => %s\t%s 130File permissions are => 100666 131File created in => directory specified 132 133-- Iteration 9 -- 134File name is => %s\t%s 135File permissions are => 100666 136File created in => temp dir 137 138-- Iteration 10 -- 139File name is => %s\t%s 140File permissions are => 100666 141File created in => temp dir 142 143-- Iteration 11 -- 144File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s 145File permissions are => 100666 146File created in => directory specified 147 148-- Iteration 12 -- 149File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s 150File permissions are => 100666 151File created in => directory specified 152 153-- Iteration 13 -- 154File name is => %s\tempnam_variation2\tempnam_variation2_sub\t%s 155File permissions are => 100666 156File created in => directory specified 157 158-- Iteration 14 -- 159File name is => %s\t%s 160File permissions are => 100666 161File created in => temp dir 162 163*** Done ***