Jump to content

Creating a list


NoticeablyFAT

Recommended Posts

Hello,

 

I am extremely new to php, so I'm having some trouble figuring out just where to start with some of this stuff, which means I don't know what to look for to figure out what I need. So, on tho the question. I have a basic script set up to open a folder, read the files, then print a list of the files, sorted by date. This is then inserted into a small frame on my website. This all works just fine. What I'd like to do is create the list, then list only the last 10 files found. What functions would I use?

Link to comment
https://forums.phpfreaks.com/topic/150535-creating-a-list/
Share on other sites

What I have so far (actual paths changed for some semblance of privacy):

 

<?

function LoadFiles($dir)

{

$Files = array();

$It = opendir($dir);

if (! $It)

die('Cannot list files for ' . $dir);

while ($Filename = readdir($It))

{

if ($Filename == '.' || $Filename == '..')

continue;

$LastModified = filemtime($dir . $Filename);

$Files[$LastModified] = $dir .$Filename;

}

 

return $Files;

}

 

$Files = LoadFiles('/home/something/public_html/somethingelse/cellpics/');

krsort($Files);

 

//Replace path that opendir will read with path that works on page

$Filepath = str_replace("/home/something/public_html/somethingelse/cellpics/", "http://mywebsite.com/cellpics/", $Files);

 

foreach ($Filepath as $key => $file){

echo '<a href="'.$file.'">'.$file.'</a><br>';

}

?>

 

I didn't write this, but I understand most of it.

Link to comment
https://forums.phpfreaks.com/topic/150535-creating-a-list/#findComment-790703
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.