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