PageRenderTime 45ms CodeModel.GetById 16ms RepoModel.GetById 0ms app.codeStats 0ms

/hphp/test/zend/good/ext/standard/tests/file/tempnam_variation1.php

http://github.com/facebook/hiphop-php
PHP | 56 lines | 43 code | 9 blank | 4 comment | 10 complexity | 34dd375648680232c49f35505da2ba63 MD5 | raw file
Possible License(s): LGPL-2.1, BSD-2-Clause, BSD-3-Clause, MPL-2.0-no-copyleft-exception, MIT, LGPL-2.0, Apache-2.0
  1. <?hh
  2. /* Prototype: string tempnam ( string $dir, string $prefix );
  3. Description: Create file with unique file name.
  4. */
  5. /* Creating number of unique files by passing a file name as prefix */
  6. <<__EntryPoint>> function main(): void {
  7. $file_path = dirname(__FILE__)."/tempnamVar1";
  8. mkdir($file_path);
  9. echo "*** Testing tempnam() in creation of unique files ***\n";
  10. $files = darray[];
  11. for($i=1; $i<=10; $i++) {
  12. echo "-- Iteration $i --\n";
  13. $files[$i] = tempnam("$file_path", "tempnam_variation1.tmp");
  14. if( file_exists($files[$i]) ) {
  15. echo "File name is => ";
  16. print($files[$i]);
  17. echo "\n";
  18. echo "File permissions are => ";
  19. printf("%o", fileperms($files[$i]) );
  20. echo "\n";
  21. clearstatcache();
  22. echo "File inode is => ";
  23. print_r( fileinode($files[$i]) ); //checking inodes
  24. echo "\n";
  25. echo "File created in => ";
  26. $file_dir = dirname($files[$i]);
  27. if ($file_dir == sys_get_temp_dir()) {
  28. echo "temp dir\n";
  29. }
  30. else if ($file_dir == $file_path) {
  31. echo "directory specified\n";
  32. }
  33. else {
  34. echo "unknown location\n";
  35. }
  36. clearstatcache();
  37. }
  38. else {
  39. print("- File is not created -");
  40. }
  41. }
  42. for($i=1; $i<=10; $i++) {
  43. unlink($files[$i]);
  44. }
  45. rmdir($file_path);
  46. echo "*** Done ***\n";
  47. }