fpassthru 


php128 apg

READS to EOF, (END-OF-FILE), on the given file pointer from the current position and writes the results to the output buffer.

To read all the file content you may need to call the function rewind.



<?php

int fpassthru 
res $stream )


where,

$stream The valid file pointer opened by fopen
                
or fsockopen and not yet closed by fclose 

?>

 $stream 


A valid file pointer to a successfully opened such as by the fopen or fsockopen and not closed by fclose.





This function returns the number of characters read from $stream and passed through to the output.



  1 EXERCISE   

<?php

define
('PAW''file://' __DIR__ '/adds/');

echo 
PAW '<br><br>';

$fl01 PAW 'love.txt';

$opts01 = [ 'https' => [ 'method'=>"POST",
          
'header' => "Accept-language: en",
          
'content' => $fl01 ] ]; 

$cntxt01 stream_context_create($opts01);

var_dump($cntxt01);

echo 
'<br><br>';

$f01 fopen($fl01"r"false$cntxt01);

rewind($f01);
// RESETS THE FILE POINTER TO THE BEGINNING

$int fpassthru($f01);
// READS TO THE EOF

echo '<br><br>' $int ' characters read.';

fclose($f01);

?>

  2 EXERCISE   

<?php

define
('PAN'__DIR__ '/adds');

echo 
PAN '<br><br>'

$fl02 PAN '/star.png';

$f02 fopen($fl02"r");

rewind($f02);
// RESETS THE FILE POINTER TO THE BEGINNING

$int fpassthru($f02);
// READS TO THE EOF

echo '<br><br>' $int ' characters read.';

fclose($f02);

?>