Due to fgetcsv read only a line from open file, or line by line if looping. As decribe below, it doesn’t able to return number of line from specific file.
Solution below may help to detect enf of file:
$this->file = fopen($this->path,"r"); if(!$this->file) { echo "Error opening data file.\n"; exit; } $row = 0; while ( ! feof($this->file) ) { $data = fgetcsv($this->file, '', ","); if(feof($this->file)) { //if end of file do somethine } if( !empty($data) ) { //if not enf of file, process data } $row++; } fclose($this->file);
What do you think?