PHP/File Directory/fseek — различия между версиями

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

Версия 10:37, 26 мая 2010

Constant Reference Points for fseek()

 
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



Moving Around a File with fseek()

 
<html>
<head>
<title>Moving Around a File with fseek()</title>
</head>
<body>
<div>
<?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 <br/>\n";
    fseek( $fp, $halfway );
    $chunk = fread( $fp, ($fsize - $halfway) );
    print $chunk;
?>
</div>
</body>
</html>



Using the fseek() Function

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