tempnam_variation5.phpt 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. --TEST--
  2. Test tempnam() function: usage variations - existing file
  3. --SKIPIF--
  4. <?php
  5. if(substr(PHP_OS, 0, 3) == "WIN")
  6. die("skip Do not run on Windows");
  7. ?>
  8. --FILE--
  9. <?php
  10. /* Passing an existing file as $prefix for tempnam() fn */
  11. $file_path = __DIR__;
  12. echo "*** Test tempnam() function: by passing an existing filename as prefix ***\n";
  13. $dir_name = $file_path."/tempnam_variation5";
  14. mkdir($dir_name);
  15. $h = fopen($dir_name."/tempnam_variation5.tmp", "w");
  16. for($i=1; $i<=3; $i++) {
  17. echo "-- Iteration $i --\n";
  18. $created_file = tempnam("$dir_name", "tempnam_variation5.tmp");
  19. if( file_exists($created_file) ) {
  20. echo "File name is => ";
  21. print($created_file);
  22. echo "\n";
  23. }
  24. else
  25. print("File is not created");
  26. unlink($created_file);
  27. }
  28. fclose($h);
  29. unlink($dir_name."/tempnam_variation5.tmp");
  30. rmdir($dir_name);
  31. echo "\n*** Done ***\n";
  32. ?>
  33. --EXPECTF--
  34. *** Test tempnam() function: by passing an existing filename as prefix ***
  35. -- Iteration 1 --
  36. File name is => %stempnam_variation5%etempnam_variation5.tmp%s
  37. -- Iteration 2 --
  38. File name is => %stempnam_variation5%etempnam_variation5.tmp%s
  39. -- Iteration 3 --
  40. File name is => %stempnam_variation5%etempnam_variation5.tmp%s
  41. *** Done ***