1

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.

Louis Lee
  • 281
  • 5
  • 15
  • A literal google search of your question gives you the answer, you can test it yourself [here](https://www.google.nl/search?q=PHP+check+if+a+file+is+EOF&oq=PHP+check+if+a+file+is+EOF&aqs=chrome..69i64j69i57.5252j0j9&sourceid=chrome&ie=UTF-8). I mean, you see for instance this thread floating by.. http://stackoverflow.com/questions/5431941/why-is-while-feof-file-always-wrong – Nytrix Jan 25 '17 at 12:35
  • i google , but the feof doesn't really return something that meaning complete or partial of the file – Louis Lee Jan 25 '17 at 12:55

1 Answers1

2

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
samayo
  • 16,163
  • 12
  • 91
  • 106