File: tempnam_variation6-win32.phpt

package info (click to toggle)
php5 5.3.3-7%2Bsqueeze17
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 122,824 kB
  • ctags: 55,742
  • sloc: ansic: 633,963; php: 19,620; sh: 11,344; xml: 5,816; cpp: 2,400; yacc: 1,745; exp: 1,514; makefile: 1,019; pascal: 623; awk: 537; sql: 22
file content (62 lines) | stat: -rw-r--r-- 1,482 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
--TEST--
Test tempnam() function: usage variations - Using previous unique filename
--CREDITS--
Dave Kelsey <d_kelsey@uk.ibm.com>
--SKIPIF--
<?php
if(substr(PHP_OS, 0, 3) != "WIN")
  die("skip Windows Only");
?> 
--FILE--
<?php
/* Prototype:  string tempnam ( string $dir, string $prefix );
   Description: Create file with unique file name.
*/

/* Trying to create unique files by passing previously created unique file name as prefix */

$file_path = dirname(__FILE__);

echo "\n*** Test tempnam(): by passing previously created filenames ***\n";
$file_name = "tempnam_variation6.tmp";
for($i=1; $i<=3; $i++) {
  echo "-- Iteration $i --\n";
  $file_name = tempnam("$file_path", $file_name);

  if( file_exists($file_name) ) {
    echo "File name is => ";
    print($file_name);
    echo "\n";
    
    echo "File created in => ";
    $file_dir = dirname($file_name);
        
    if ($file_dir == sys_get_temp_dir()) {
       echo "temp dir\n";
    }
    else if ($file_dir == $file_path) {
       echo "directory specified\n";
    }
    else {
       echo "unknown location\n";
    }    
 }

  unlink($file_name);
}

echo "\n*** Done ***\n";
?>
--EXPECTF--
*** Test tempnam(): by passing previously created filenames ***
-- Iteration 1 --
File name is => %s%et%s
File created in => directory specified
-- Iteration 2 --
File name is => %s%et%s
File created in => directory specified
-- Iteration 3 --
File name is => %s%et%s
File created in => directory specified

*** Done ***