Reading Most Recent CSV File in Directory


Posted on 16th Feb 2014 07:03 pm 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?

No comments posted yet

Your Answer:

Login to answer
164 Like 26 Dislike
Previous forums Next forums
Other forums

Random Number Generation And Probability
Hello, I am working on a function which has to insert data into a SQL table.

we have to suppl

sendmail code suddenly not working
Hi Guys, I maintain 3 sites (including my own) I use the following code from a french webmaster that

Passing Arguments to execlp()
I'm writing a program that mimics a unix shell. It's supposed to take commands with arguments and ex

HTAccess auto log in?
Hi all.

Too busy driving celebs about lately so I hope someone here can help me out.

I

Create PHP table grid help, please
I have a MySQL database setup, now it's time for the table (gridview) design in php. Here's the prob

Form submissing with PHP and JQuery/Ajax
I have searched everywhere, but cannot find a solution for this... I have worked all day trying to g

Get value from Select menu
Hi!

Have tried to find the solution on the web. Don't know if there is an easy one. A descrip

Date Format
Hi there,

I have a date format like this right now:
Sat, 17 Oct 2009 17:04:00

I ne

PHP Surveys
I really would like some advice.

If you have a client come to you asking for a survey to be d

phph within href not showing php if change ? to &
Code: [Select]<a href="<?php echo $puser; ?>?m=<?php=(($m-1)&l

Sign up to write
Sign up now if you have flare of writing..
Login   |   Register
Follow Us
Indyaspeak @ Facebook Indyaspeak @ Twitter Indyaspeak @ Pinterest RSS



Play Free Quiz and Win Cash