PHP/File Directory/fseek

Материал из Web эксперт
Перейти к: навигация, поиск

Constant Reference Points for fseek()

   <source lang="html4strict">

SEEK_SET (Default) the beginning of the file

SEEK_CUR The current location of the file pointer

SEEK_END One byte past the end of the file

 </source>
   
  


Moving Around a File with fseek()

   <source lang="html4strict">

<html> <head> <title>Moving Around a File with fseek()</title> </head> <body>

<?php

   $filename = "data.txt";
   $fp = fopen( $filename, "r" ) or die("Couldn"t open $filename");
   $fsize = filesize($filename);
   $halfway = (int)( $fsize / 2 );
   print "Halfway point: $halfway 
\n"; fseek( $fp, $halfway ); $chunk = fread( $fp, ($fsize - $halfway) ); print $chunk;

?>

</body> </html>

 </source>
   
  


Using the fseek() Function

   <source lang="html4strict">

<?php

    $fr = fopen("data.dat", "r");
    if(!$fr) exit;
    fseek($fr, 10);
    fseek($fr, -10, SEEK_END);
    fseek($fr, 2, SEEK_CUR);

?>

 </source>