tempnam_variation3.phpt 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. --TEST--
  2. Test tempnam() function: usage variations - obscure prefixes
  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. /* Prototype: string tempnam ( string $dir, string $prefix );
  11. Description: Create file with unique file name.
  12. */
  13. /* Passing invalid/non-existing args for $prefix */
  14. echo "*** Testing tempnam() with obscure prefixes ***\n";
  15. $file_path = dirname(__FILE__)."/tempnamVar3";
  16. mkdir($file_path);
  17. /* An array of prefixes */
  18. $names_arr = array(
  19. /* Invalid args */
  20. -1,
  21. TRUE,
  22. FALSE,
  23. NULL,
  24. "",
  25. " ",
  26. "\0",
  27. array(),
  28. /* prefix with path separator of a non existing directory*/
  29. "/no/such/file/dir",
  30. "php/php"
  31. );
  32. for( $i=0; $i<count($names_arr); $i++ ) {
  33. echo "-- Iteration $i --\n";
  34. $file_name = tempnam("$file_path", $names_arr[$i]);
  35. /* creating the files in existing dir */
  36. if( file_exists($file_name) ) {
  37. echo "File name is => ";
  38. print($file_name);
  39. echo "\n";
  40. echo "File permissions are => ";
  41. printf("%o", fileperms($file_name) );
  42. echo "\n";
  43. echo "File created in => ";
  44. $file_dir = dirname($file_name);
  45. if ($file_dir == sys_get_temp_dir()) {
  46. echo "temp dir\n";
  47. }
  48. else if ($file_dir == $file_path) {
  49. echo "directory specified\n";
  50. }
  51. else {
  52. echo "unknown location\n";
  53. }
  54. }
  55. else {
  56. echo "-- File is not created --\n";
  57. }
  58. unlink($file_name);
  59. }
  60. rmdir($file_path);
  61. echo "\n*** Done ***\n";
  62. ?>
  63. --EXPECTF--
  64. *** Testing tempnam() with obscure prefixes ***
  65. -- Iteration 0 --
  66. File name is => %s/%s
  67. File permissions are => 100600
  68. File created in => directory specified
  69. -- Iteration 1 --
  70. File name is => %s/%s
  71. File permissions are => 100600
  72. File created in => directory specified
  73. -- Iteration 2 --
  74. File name is => %s/%s
  75. File permissions are => 100600
  76. File created in => directory specified
  77. -- Iteration 3 --
  78. File name is => %s/%s
  79. File permissions are => 100600
  80. File created in => directory specified
  81. -- Iteration 4 --
  82. File name is => %s/%s
  83. File permissions are => 100600
  84. File created in => directory specified
  85. -- Iteration 5 --
  86. File name is => %s/%s
  87. File permissions are => 100600
  88. File created in => directory specified
  89. -- Iteration 6 --
  90. Warning: tempnam() expects parameter 2 to be a valid path, string given in %s on line %d
  91. -- File is not created --
  92. Warning: unlink(): %s in %s on line %d
  93. -- Iteration 7 --
  94. Warning: tempnam() expects parameter 2 to be a valid path, array given in %s on line %d
  95. -- File is not created --
  96. Warning: unlink(): %s in %s on line %d
  97. -- Iteration 8 --
  98. File name is => %s/dir%s
  99. File permissions are => 100600
  100. File created in => directory specified
  101. -- Iteration 9 --
  102. File name is => %s/php%s
  103. File permissions are => 100600
  104. File created in => directory specified
  105. *** Done ***