duanfeiqu1989 2017-01-25 12:30 采纳率: 100%
浏览 30

PHP - 检查文件是否为EOF

Is it possible to check whether a file is completed(EOF) or is partially(corrupted)

I try :

$_file = @fopen($filePath, "r");
$isComplete = feof($_file);
fclose($file);

but it return empty.

  • 写回答

1条回答 默认 最新

  • drj26159 2017-01-25 12:33
    关注

    You can use a while(){} loop for that, as:

    $fh = fopen("alphabets.txt", "r"); 
    while (!feof($fh)) { 
        $line = fgets($fh); 
        echo $line . "<br/>";
    }
    
    echo 'File is completed <br />';
    

    Which will obviosuly iterate through the file's line one by one and exits as it reaches the end

    I assuming your file contains a letters from a-h, this will be your output

    a 
    b 
    c 
    d 
    e 
    f 
    g 
    h
    File is completed
    
    评论

报告相同问题?