tempnam_variation1-win32.phpt 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. --TEST--
  2. Test tempnam() function: usage variations - creating files
  3. --SKIPIF--
  4. <?php
  5. if(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. /* Creating number of unique files by passing a file name as prefix */
  14. $file_path = dirname(__FILE__)."/tempnamVar1";
  15. mkdir($file_path);
  16. echo "*** Testing tempnam() in creation of unique files ***\n";
  17. for($i=1; $i<=10; $i++) {
  18. echo "-- Iteration $i --\n";
  19. $files[$i] = tempnam("$file_path", "tempnam_variation1.tmp");
  20. if( file_exists($files[$i]) ) {
  21. echo "File name is => ";
  22. print($files[$i]);
  23. echo "\n";
  24. echo "File permissions are => ";
  25. printf("%o", fileperms($files[$i]) );
  26. echo "\n";
  27. clearstatcache();
  28. echo "File created in => ";
  29. $file_dir = dirname($files[$i]);
  30. if (realpath($file_dir) == realpath(sys_get_temp_dir()) || realpath($file_dir."\\") == realpath(sys_get_temp_dir())) {
  31. echo "temp dir\n";
  32. }
  33. else if (realpath($file_dir) == realpath($file_path) || realpath($file_dir."\\") == realpath($file_path)) {
  34. echo "directory specified\n";
  35. }
  36. else {
  37. echo "unknown location\n";
  38. }
  39. clearstatcache();
  40. }
  41. else {
  42. print("- File is not created -");
  43. }
  44. }
  45. for($i=1; $i<=10; $i++) {
  46. unlink($files[$i]);
  47. }
  48. rmdir($file_path);
  49. echo "*** Done ***\n";
  50. ?>
  51. --EXPECTF--
  52. *** Testing tempnam() in creation of unique files ***
  53. -- Iteration 1 --
  54. File name is => %s%et%s
  55. File permissions are => 100666
  56. File created in => directory specified
  57. -- Iteration 2 --
  58. File name is => %s%et%s
  59. File permissions are => 100666
  60. File created in => directory specified
  61. -- Iteration 3 --
  62. File name is => %s%et%s
  63. File permissions are => 100666
  64. File created in => directory specified
  65. -- Iteration 4 --
  66. File name is => %s%et%s
  67. File permissions are => 100666
  68. File created in => directory specified
  69. -- Iteration 5 --
  70. File name is => %s%et%s
  71. File permissions are => 100666
  72. File created in => directory specified
  73. -- Iteration 6 --
  74. File name is => %s%et%s
  75. File permissions are => 100666
  76. File created in => directory specified
  77. -- Iteration 7 --
  78. File name is => %s%et%s
  79. File permissions are => 100666
  80. File created in => directory specified
  81. -- Iteration 8 --
  82. File name is => %s%et%s
  83. File permissions are => 100666
  84. File created in => directory specified
  85. -- Iteration 9 --
  86. File name is => %s%et%s
  87. File permissions are => 100666
  88. File created in => directory specified
  89. -- Iteration 10 --
  90. File name is => %s%et%s
  91. File permissions are => 100666
  92. File created in => directory specified
  93. *** Done ***