I know there is a better way to do this.
Posted: Thu Jul 21, 2005 8:50 am
Hi. I am new to php programming, and i need a way to select the last file in the directory. (actually, i would like to select the newest/most recent file, but i got this working first.) Here is how i did, but i know there has to be a much more elegant way to do so... any suggestions are very appreciated.
Code: Select all
<?php
$filelist = array();
$x=0;
if ($handle = opendir('./coupons')) {
while (false !== ($file = readdir($handle))) {
if ($file != "." && $file != "..") {
$filelist[$x] = $file;
$x++;
}
}
echo end($filelist);
closedir($handle);
}
?>