图像作为PHP文件
我对PHP相当陌生,我需要知道如何将文件显示为图像。例如,打开将显示一个图像 我的理由是我需要把它放在图像作为PHP文件,php,image,Php,Image,我对PHP相当陌生,我需要知道如何将文件显示为图像。例如,打开将显示一个图像 我的理由是我需要把它放在的src属性中。我希望图像根据时间进行更改 我目前有3个图像之间的循环 我目前拥有的: <?php $w = date('W'); # week $d = date('N'); # day $t = date('G'); # time dealWithTime($d); function
的src
属性中。我希望图像根据时间进行更改
我目前有3个图像之间的循环
我目前拥有的:
<?php
$w = date('W'); # week
$d = date('N'); # day
$t = date('G'); # time
dealWithTime($d);
function dealWithTime(day) {
if (day == 1) {
# Monday
if ($w == 13) {
# Week 13
} else if ($w == 14) {
# Week 14
if ($t >= 0 && $t <= 6) {
# Image = 1.png
} else if ($t > 6 && $t <= 10) {
# Image = 2.png
} else if ($t > 10 && $t <= 14) {
# Image = 3.png
} else if ($t > 14 && $t <= 18) {
# Image = 1.png
} else if ($t > 18) {
# Image = 2.png
}
}
} else if (day == 2) {
# Tuesday
} else if (day == 3) {
# Wednesday
} else if (day == 4) {
# Thursday
} else if (day == 5) {
# Friday
} else if (day == 6) {
# Saturday
} else if (day == 7) {
# Sunday
}
}
?>
使用PHP的GD库。PHP网站上有一些例子可以帮助您入门:
首先,您对
src
部分的理解是正确的。您可以简单地使用.php
文件作为图像的src,并显示一个漂亮的图像。因此,一旦您确定了要向用户显示的图像,以下是一些方法:
301
,因为现在的浏览器缓存永久重定向李>
完成逻辑后,让PHP设置script.PHP的内容类型 现在script.php的内容类型是默认的
text/html
——但您希望它显示图像,因此需要执行以下操作:
header( "Content-type: image/png" );
然后,从逻辑中得到的任何文件中,我都会使用file\u get\u contents()
函数和echo
或print()
图像。希望对您有很大帮助。