/    Sign up×
Community /Pin to ProfileBookmark

Returning an jpg by date

I’m not very good at php right now but I have a friend that has asked me if I knew how to solve a problem he had.

What would be the code to return a certian premade image depending on the date.

ex. Morning display this image
noon display this image
night display this image

This is primarly for forums.

I was thinking soemthing like using date and 3 or 4 if else but I dont’ know how to return an image. I’m still learning.

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@ShrineDesignsApr 14.2005 — try this[code=php]<?php
$noon = mktime(12, 0, 0);
$evening = mktime(6, 0, 0);

if(time() < $noon)
{
// output morning image
}
if(time() >= $noon && time() < $evening)
{
// output afternoon image
}
if(time() >= $evening)
{
// output evening image
}
?>[/code]
Copy linkTweet thisAlerts:
@FrozenDiceauthorApr 15.2005 — ? Thanks. I am still at a loss about how to output the images though. I was going to use the date function but mktime seems better. I should have made my request more specific.

I don't know how to make php return a single image file.
Copy linkTweet thisAlerts:
@JayMApr 15.2005 — :D Thanks. I am still at a loss about how to output the images though. I was going to use the date function but mktime seems better. I should have made my request more specific.

I don't know how to make php return a single image file.[/QUOTE]

You could always resort to simple HTML.

Just use the closing ?> tag after each statement and use <img src="yoursite.html">. Don't forget to re-open your <?php tag before the next if statement.
Copy linkTweet thisAlerts:
@ShrineDesignsApr 15.2005 — call this from within an <img src="image.php" width="200" height="200" alt="" /> tag[code=php]<?php
$noon = mktime(12, 0, 0);
$evening = mktime(6, 0, 0);

if(time() < $noon)
{
$im = 'path/to/morning.jpg';
}
if(time() >= $noon && time() < $evening)
{
$im = 'path/to/noon.jpg';
}
if(time() >= $evening)
{
$im = 'path/to/nite.jpg';
}
list(, , $type) = getimagesize($im);
$mime = image_type_to_mime_type($type);
header("Content-type: $mime");
exit(readfile($im));
?>[/code]
×

Success!

Help @FrozenDice spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...