Jump to content

different coloured symbol for recently uploaded pics


busnut

Recommended Posts

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!"; 

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...

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

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?

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
}

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 "---"

<?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)

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.