fpassthru_variation.phpt 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. --TEST--
  2. Test fpassthru() function: Variations
  3. --FILE--
  4. <?php
  5. echo "*** Testing fpassthru() function with files ***\n\n";
  6. echo "--- Testing with different offsets ---\n";
  7. $file_name = __DIR__."/passthru_variation.tmp";
  8. $file_write = fopen($file_name, "w");
  9. fwrite($file_write, "1234567890abcdefghijklmnopqrstuvwxyz");
  10. fclose($file_write);
  11. $file_read = fopen($file_name, "r");
  12. $offset_arr = array(
  13. /* Positive offsets */
  14. 0,
  15. 1,
  16. 5,
  17. 10,
  18. 20,
  19. 30,
  20. 35,
  21. 36,
  22. 70,
  23. /* Negative offsets, the file pointer should be at the end of file
  24. to get data */
  25. -1,
  26. -5,
  27. -10,
  28. -20,
  29. -35,
  30. -36,
  31. -70
  32. );
  33. for( $i=0; $i<count($offset_arr); $i++ ) {
  34. echo "-- Iteration $i --\n";
  35. if( $offset_arr[$i] >= 0 ) {
  36. fseek($file_read, $offset_arr[$i], SEEK_SET);
  37. var_dump(fpassthru($file_read) );
  38. rewind( $file_read );
  39. }else
  40. {
  41. fseek($file_read, $offset_arr[$i], SEEK_END);
  42. var_dump( fpassthru($file_read) );
  43. rewind( $file_read );
  44. }
  45. }
  46. fclose($file_read); // closing the handle
  47. echo "\n--- Testing with binary mode file ---\n";
  48. /* Opening the file in binary read mode */
  49. $file_read = fopen($file_name, "rb");
  50. fseek($file_read, 12, SEEK_SET);
  51. var_dump(fpassthru($file_read) );
  52. rewind( $file_read );
  53. fclose($file_read);
  54. unlink($file_name);
  55. echo "\n*** Done ***\n";
  56. ?>
  57. --EXPECT--
  58. *** Testing fpassthru() function with files ***
  59. --- Testing with different offsets ---
  60. -- Iteration 0 --
  61. 1234567890abcdefghijklmnopqrstuvwxyzint(36)
  62. -- Iteration 1 --
  63. 234567890abcdefghijklmnopqrstuvwxyzint(35)
  64. -- Iteration 2 --
  65. 67890abcdefghijklmnopqrstuvwxyzint(31)
  66. -- Iteration 3 --
  67. abcdefghijklmnopqrstuvwxyzint(26)
  68. -- Iteration 4 --
  69. klmnopqrstuvwxyzint(16)
  70. -- Iteration 5 --
  71. uvwxyzint(6)
  72. -- Iteration 6 --
  73. zint(1)
  74. -- Iteration 7 --
  75. int(0)
  76. -- Iteration 8 --
  77. int(0)
  78. -- Iteration 9 --
  79. zint(1)
  80. -- Iteration 10 --
  81. vwxyzint(5)
  82. -- Iteration 11 --
  83. qrstuvwxyzint(10)
  84. -- Iteration 12 --
  85. ghijklmnopqrstuvwxyzint(20)
  86. -- Iteration 13 --
  87. 234567890abcdefghijklmnopqrstuvwxyzint(35)
  88. -- Iteration 14 --
  89. 1234567890abcdefghijklmnopqrstuvwxyzint(36)
  90. -- Iteration 15 --
  91. 1234567890abcdefghijklmnopqrstuvwxyzint(36)
  92. --- Testing with binary mode file ---
  93. cdefghijklmnopqrstuvwxyzint(24)
  94. *** Done ***