tempnam_variation7.phpt 2.8 KB

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