busnut Posted May 8, 2009 Share Posted May 8, 2009 G'day A part of my site has a script that if a photo exists for a particular bus that is being searched, it will display a little image that is clickable to indicate that a photo is available, but what I want to do if it is possible is that if the photo was uploaded within the last week for instance, it would show a different coloured symbol instead? I'm guessing it would either check against the exif info or the file info of the date, but unsure how to do it. Here is the current script if anyone is able to do anything to it for me. if (file_exists ("photos/".$result['chassisbody']."/".$result['busno'].".jpg")) { echo "<a href=\"photos/".$result['chassisbody']."/".$result['busno'].".jpg\" rel=\"lightbox\" title=\"bus ".$result['busno']." - ".$result['chassisbody']."\" border=1><img src='photos/".$result['chassisbody']."/".$result['busno'].".jpg' border=0 width=300></a>"; } else echo "Sorry, no picture available for this bus!"; Link to comment https://forums.phpfreaks.com/topic/157345-different-coloured-symbol-for-recently-uploaded-pics/ Share on other sites More sharing options...
gevans Posted May 8, 2009 Share Posted May 8, 2009 The easiest way would be to add a datetime field to your db table. Then you just call this and see if that date is within the last week and output your symbol as appropriate! Link to comment https://forums.phpfreaks.com/topic/157345-different-coloured-symbol-for-recently-uploaded-pics/#findComment-829349 Share on other sites More sharing options...
busnut Posted May 8, 2009 Author Share Posted May 8, 2009 The easiest way would be to add a datetime field to your db table. Then you just call this and see if that date is within the last week and output your symbol as appropriate! Does that mean adding another field to the table and when i upload an image of a particular bus, I then have to update the table (or moreso bus that ive just uploaded the photo)? If so, i'll probably forget the idea. I just thought there is/was a way for the script to read the info of the image file and go from there... Link to comment https://forums.phpfreaks.com/topic/157345-different-coloured-symbol-for-recently-uploaded-pics/#findComment-829360 Share on other sites More sharing options...
Axeia Posted May 8, 2009 Share Posted May 8, 2009 you could add a field to the database like DATETIME DEFAULT NOW() Then it would enter the value itself if left blank. You could also use the last modified file property if the image is left untouched once uploaded Link to comment https://forums.phpfreaks.com/topic/157345-different-coloured-symbol-for-recently-uploaded-pics/#findComment-829364 Share on other sites More sharing options...
gevans Posted May 8, 2009 Share Posted May 8, 2009 It would actaully be raelly easy if you've already built the system. The sql for the field would be; ALTER TABLE `your-table-here` ADD `uploaded` DATETIME NOT NULL Then your query; SELECT DATEDIFF(NOW(), `uploaded`) AS num_days FROM `your-table-here` Then with the retrieved details; <?php echo $details['num_days'];//prints the number of days difference if($details['num_days'] > 7){ //over a week }else{ //less than a week } None of that is tested, but should work fine. Just have a play Link to comment https://forums.phpfreaks.com/topic/157345-different-coloured-symbol-for-recently-uploaded-pics/#findComment-829368 Share on other sites More sharing options...
busnut Posted May 8, 2009 Author Share Posted May 8, 2009 I have to admit, the last bit of sql code has lost me as i'm still learning (at a slow rate), but what i've done so far as a test is this: $last_modified = filemtime("photos/".$result['chassisbody']."/".$result['busno'].".jpg"); if (file_exists ("photos/".$result['chassisbody']."/".$result['busno'].".jpg")) { echo "<a href=\"photos/".$result['chassisbody']."/".$result['busno'].".jpg\" rel=\"lightbox\" title=\"bus ".$result['busno']." - ".$result['chassisbody']."\" border=1><img src='photos/".$result['chassisbody']."/".$result['busno'].".jpg' border=0 width=300></a>"; } else echo "Sorry, no picture available for this bus!"; echo "<br>Photo uploaded on: "; print(date("d/m/Y", $last_modified)); now what i'm trying to do, but not with much sucess is a 'if' statement, something like if $todaysdate > $last_modified - 7 days, then echo "this" otherwise echo "this". So any ideas on how to get the if statement to work correctly for me? Link to comment https://forums.phpfreaks.com/topic/157345-different-coloured-symbol-for-recently-uploaded-pics/#findComment-829373 Share on other sites More sharing options...
gevans Posted May 8, 2009 Share Posted May 8, 2009 Well filetime() returns a timestamp so we can do it really easily... <?php $last_modified = filemtime("photos/".$result['chassisbody']."/".$result['busno'].".jpg"); $one_week = 60*60*24*7;(60 seconds x 60 minutes x 24 hours x 7 days) if((timestamp()-$last_modified)<$one_week) { //in the last seven days }else{ //not in the last seven days } Link to comment https://forums.phpfreaks.com/topic/157345-different-coloured-symbol-for-recently-uploaded-pics/#findComment-829384 Share on other sites More sharing options...
busnut Posted May 8, 2009 Author Share Posted May 8, 2009 Well filetime() returns a timestamp so we can do it really easily... <?php $last_modified = filemtime("photos/".$result['chassisbody']."/".$result['busno'].".jpg"); $one_week = 60*60*24*7;(60 seconds x 60 minutes x 24 hours x 7 days) if((timestamp()-$last_modified)<$one_week) { //in the last seven days }else{ //not in the last seven days } Ah, that makes alot more sense, although I did come up with my own theory, but alot more long winded with probably stuff that really shouldn't be in there, althoug the question is asked, if the file doesn't exist, its suppose to show "---" So really there are if under 7 days, then this, if over 7 days then that, but if nothing, then "---" Link to comment https://forums.phpfreaks.com/topic/157345-different-coloured-symbol-for-recently-uploaded-pics/#findComment-829395 Share on other sites More sharing options...
gevans Posted May 8, 2009 Share Posted May 8, 2009 <?php $last_modified = filemtime("photos/".$result['chassisbody']."/".$result['busno'].".jpg"); if(file_exists ("photos/".$result['chassisbody']."/".$result['busno'].".jpg")) { echo "<a href=\"photos/".$result['chassisbody']."/".$result['busno'].".jpg\" rel=\"lightbox\" title=\"bus ".$result['busno']." - ".$result['chassisbody']."\" border=1><img src='photos/".$result['chassisbody']."/".$result['busno'].".jpg' border=0 width=300></a>"; $one_week = 60*60*24*7;(60 seconds x 60 minutes x 24 hours x 7 days); if((timestamp()-$last_modified)<$one_week) { //in the last seven days }else{ //not in the last seven days } } else { echo "Sorry, no picture available for this bus!"; } That way you can print anything you want for the symbol (if anything) Link to comment https://forums.phpfreaks.com/topic/157345-different-coloured-symbol-for-recently-uploaded-pics/#findComment-829412 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.