Jump to content

Display last modified image in a directory?


shadysaiyan

Recommended Posts

I believe you should use the readdir() and filemtime() functions.

 

$lastmtime = 0;
$lastfname = 

if ($dh = opendir("../upload/")) {
   while (false !== ($file = readdir($dh))) {
       if (filemtime($file) > $lastmtime) {
           $lastmtime = filemtime($file);
           $lastfname = $file;
       }
   }
}

echo "<img src='../upload/$lastfname' />";

 

I haven't tested this but I think it'd work.

Sorry, for replying so late >_< forgot i posted this.

 

@adam - idk how, i pretty much work and modify off of what people give me

 

@michael -  when i run it, i get and

 

Parse error: syntax error, unexpected T_IF in /home/content/s/h/a/shadysaiyan/html/idcards/lastcardortag.php on line 5

 

I checked over the beginners guide to debuggin, and i dont see a missing ; or unclosed quotes/brackets

Sorry, for replying so late >_< forgot i posted this.

 

@adam - idk how, i pretty much work and modify off of what people give me

 

@michael -  when i run it, i get and

 

Parse error: syntax error, unexpected T_IF in /home/content/s/h/a/shadysaiyan/html/idcards/lastcardortag.php on line 5

 

I checked over the beginners guide to debuggin, and i dont see a missing ; or unclosed quotes/brackets

 

$lastfname =

 

It needs a value and a ;

$lastmtime = 0;
$lastfname = "";

if ($dh = opendir("../upload/")) {
    while (false !== ($file = readdir($dh))) {
        if (filemtime($file) > $lastmtime) {
            $lastmtime = filemtime($file);
            $lastfname = $file;
        }
    }
}

echo "<img src='../upload/$lastfname' />";

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.