readfile_variation2.phpt 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. --TEST--
  2. Test readfile() function: usage variations - links
  3. --SKIPIF--
  4. <?php
  5. if (substr(PHP_OS, 0, 3) == 'WIN') {
  6. die('skip.. only on Linux');
  7. }
  8. ?>
  9. --FILE--
  10. <?php
  11. /* Prototype: int readfile ( string $filename [, bool $use_include_path [, resource $context]] );
  12. Description: Outputs a file
  13. */
  14. /* Variation 2 : Create file
  15. Create soft/hard link to it
  16. Read link using readfile()
  17. Delete file and its link
  18. */
  19. // include file.inc
  20. require("file.inc");
  21. $file_path = dirname(__FILE__);
  22. // temp file used here
  23. $filename = "$file_path/readfile_variation2.tmp";
  24. // create temp file and insert data into it
  25. $fp = fopen($filename, "w");
  26. fill_file($fp, "text_with_new_line", 50);
  27. fclose($fp);
  28. // temp link name used
  29. $linkname = "$file_path/readfile_variation2_link.tmp";
  30. /* Checking readfile() operation on soft link */
  31. echo "*** Testing readfile() on soft link ***\n";
  32. // create soft link to $filename
  33. var_dump( symlink($filename, $linkname) );
  34. // readfile() on soft link
  35. $count = readfile($linkname); // with default args
  36. echo "\n";
  37. var_dump($count);
  38. // delete link
  39. unlink($linkname);
  40. /* Checking readfile() operation on hard link */
  41. echo "\n*** Testing readfile() on hard link ***\n";
  42. // create hard link to $filename
  43. var_dump( link($filename, $linkname) );
  44. // readfile() on hard link
  45. $count = readfile($linkname); // default args
  46. echo "\n";
  47. var_dump($count);
  48. // delete link
  49. unlink($linkname);
  50. echo "Done\n";
  51. ?>
  52. --CLEAN--
  53. <?php
  54. $file_path = dirname(__FILE__);
  55. unlink("$file_path/readfile_variation2.tmp");
  56. ?>
  57. --EXPECTF--
  58. *** Testing readfile() on soft link ***
  59. bool(true)
  60. line
  61. line of text
  62. line
  63. line of text
  64. line
  65. line of t
  66. int(50)
  67. *** Testing readfile() on hard link ***
  68. bool(true)
  69. line
  70. line of text
  71. line
  72. line of text
  73. line
  74. line of t
  75. int(50)
  76. Done