2 Test fpassthru() function: Variations
6 Prototype: int fpassthru ( resource $handle );
7 Description: Reads to EOF on the given file pointer from the current position
8 and writes the results to the output buffer.
11 echo "*** Testing fpassthru() function with files ***\n\n";
13 echo "--- Testing with different offsets ---\n";
15 $file_name = dirname(__FILE__)."/passthru.tmp";
16 $file_write = fopen($file_name, "w");
17 fwrite($file_write, "1234567890abcdefghijklmnopqrstuvwxyz");
20 $file_read = fopen($file_name, "r");
23 /* Positive offsets */
33 /* Negative offsets, the file pointer should be at the end of file
44 for( $i=0; $i<count($offset_arr); $i++ ) {
45 echo "-- Iteration $i --\n";
46 if( $offset_arr[$i] >= 0 ) {
47 fseek($file_read, $offset_arr[$i], SEEK_SET);
48 var_dump(fpassthru($file_read) );
52 fseek($file_read, $offset_arr[$i], SEEK_END);
53 var_dump( fpassthru($file_read) );
58 fclose($file_read); // closing the handle
60 echo "\n--- Testing with binary mode file ---\n";
61 /* Opening the file in binary read mode */
62 $file_read = fopen($file_name, "rb");
64 fseek($file_read, 12, SEEK_SET);
65 var_dump(fpassthru($file_read) );
71 echo "\n*** Done ***\n";
75 *** Testing fpassthru() function with files ***
77 --- Testing with different offsets ---
79 1234567890abcdefghijklmnopqrstuvwxyzint(36)
81 234567890abcdefghijklmnopqrstuvwxyzint(35)
83 67890abcdefghijklmnopqrstuvwxyzint(31)
85 abcdefghijklmnopqrstuvwxyzint(26)
87 klmnopqrstuvwxyzint(16)
103 ghijklmnopqrstuvwxyzint(20)
105 234567890abcdefghijklmnopqrstuvwxyzint(35)
107 1234567890abcdefghijklmnopqrstuvwxyzint(36)
109 1234567890abcdefghijklmnopqrstuvwxyzint(36)
111 --- Testing with binary mode file ---
112 cdefghijklmnopqrstuvwxyzint(24)