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