We have this telemetry device that update data by sending csv file to our server. The data will be automatically updated every 15 minutes inside csv file. A new csv file will be uploaded everyday. The file will be stored in one folder every month, means that a new folder will be automatically created by the device. (for example the file path: ..\database\AWLR\2018\10)
CSV file name is a date format (for example: 20181002.CSV). Sometimes the data will not be updated since we place the device in a remote area, so if possible i want to display the latest data instead.
I want to display the newest data in table in a website automatically. I try to open csv file in array using php, but the code only display the first row (oldest data) of csv file while i want to display the last row (newest data).
Code that I have tried
$files_location = "database/";
function latest_file_Name ($files_location) {
$openDir = opendir($files_location);
while (false !== ($fileName = readdir($openDir))) {
if($fileName != "." && $fileName != "..")
{
$list[date("YmdHis ", filemtime($files_location.$fileName))]=$fileName;
}
}
rsort($list);
$last_file =array_shift($list);
return $last_file;
}
$last_file_in_folder = latest_file_Name($files_location);
pre_r($last_file_in_folder);//newest file name
$f_pointer=fopen("database/".$last_file_in_folder,"r"); // file pointer
$ar=fgetcsv($f_pointer);
pre_r($ar);//display data of newest file in array
Is there a way to display the newest data using php or any other languange/method? Any help would be appreciated
Here is a link for csv file csv