Reading Most Recent CSV File in Directory

Posted on 16th Feb 2014 by admin

I thought I had wrapped this project up, but found out that the program I use to FTP a csv file to my website is best used in time stamp mode.

That is, each day a newly named csv file is uploaded with that days data.

I currently have this script that I use to display the data on my website:

PHP Code:

echo "<table align='left' width='685' bordercolor='ccc' border='1'>";
echo "<tr><td><strong>Date</strong></td><td><strong>MPSAS</strong></td><td><strong>NELM</strong></td><td><strong>Temp (C)</strong></td></td>";
$file = "myfile.csv";
$content=file("$file");
for ($i = count($content) - 1; $i >=1 ; $i--) {
$row = explode(",", $content[$i]);
echo "<tr><td>{$row[0]}</td><td>{$row[1]}</td><td>{$row[2]}</td><td>{$row[7]}</td></td>";}echo "</table>";
?>


To read the most recent file I know I need to list the dir contents, sort, and then select the newest file, but I need some help getting started.

Anyone have experience with that is willing to help me out?

Other forums