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