shadysaiyan Posted September 26, 2008 Share Posted September 26, 2008 Is there a way to do this in PHP? ifso how please Link to comment https://forums.phpfreaks.com/topic/125916-display-last-modified-image-in-a-directory/ Share on other sites More sharing options...
adam291086 Posted September 26, 2008 Share Posted September 26, 2008 you could use the php function getlastmod() then using dates work out which one was modified last and then display it. Link to comment https://forums.phpfreaks.com/topic/125916-display-last-modified-image-in-a-directory/#findComment-651123 Share on other sites More sharing options...
michaeln82 Posted September 26, 2008 Share Posted September 26, 2008 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. Link to comment https://forums.phpfreaks.com/topic/125916-display-last-modified-image-in-a-directory/#findComment-651125 Share on other sites More sharing options...
shadysaiyan Posted September 29, 2008 Author Share Posted September 29, 2008 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 Link to comment https://forums.phpfreaks.com/topic/125916-display-last-modified-image-in-a-directory/#findComment-652712 Share on other sites More sharing options...
unrelenting Posted September 29, 2008 Share Posted September 29, 2008 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 ; Link to comment https://forums.phpfreaks.com/topic/125916-display-last-modified-image-in-a-directory/#findComment-652726 Share on other sites More sharing options...
shadysaiyan Posted September 29, 2008 Author Share Posted September 29, 2008 idk what value to give it, i thought the IF statements was assigned to to it. Link to comment https://forums.phpfreaks.com/topic/125916-display-last-modified-image-in-a-directory/#findComment-653222 Share on other sites More sharing options...
shadysaiyan Posted September 30, 2008 Author Share Posted September 30, 2008 *bump* Link to comment https://forums.phpfreaks.com/topic/125916-display-last-modified-image-in-a-directory/#findComment-654278 Share on other sites More sharing options...
QuietWhistler Posted September 30, 2008 Share Posted September 30, 2008 $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' />"; Link to comment https://forums.phpfreaks.com/topic/125916-display-last-modified-image-in-a-directory/#findComment-654281 Share on other sites More sharing options...
shadysaiyan Posted October 5, 2008 Author Share Posted October 5, 2008 That worked but how do i make it file specific? (ex. PNG, JPG, GIF, etc.) Link to comment https://forums.phpfreaks.com/topic/125916-display-last-modified-image-in-a-directory/#findComment-657706 Share on other sites More sharing options...
AndyB Posted October 5, 2008 Share Posted October 5, 2008 That worked but how do i make it file specific? (ex. PNG, JPG, GIF, etc.) glob() - http://ca.php.net/manual/en/function.glob.php - such a useful function Link to comment https://forums.phpfreaks.com/topic/125916-display-last-modified-image-in-a-directory/#findComment-657709 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.