Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/252.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
图像作为PHP文件_Php_Image - Fatal编程技术网

图像作为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

我对PHP相当陌生,我需要知道如何将文件显示为图像。例如,打开将显示一个图像

我的理由是我需要把它放在
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()
    图像。

    希望对您有很大帮助。