【问题标题】:PHP Dynamic Image LoadPHP 动态图像加载
【发布时间】:2015-01-12 01:10:08
【问题描述】:

我从一段时间以来一直在尝试显示用 php 创建的动态图像。 我尝试了不同的教程,但它们都不起作用。我做的最后一次尝试是这样的:

image.php

session_start();
$string = "bla";
$img = imagecreatetruecolor(80,15);
$font_color = imagecolorallocate($img,13,28,91);
$bg_color = imagecolorallocate($img,162,162,162);
imagefill($img,0,0,$bg_color);
imagestring($img, 3, 2, 0, $string, $font_color);
header("Content-type: image/png");
imagepng($img);
imagedestroy($img);

test.php

<html>
    <head>
        <meta charset="UTF-8">
        <title></title>
    </head>
    <body>
        <?php
        session_start();
        echo '<img src="image.php" />';
        ?>
    </body>
</html>

保存图像正在工作,我真的不明白我做错了什么,所以它加载动态。提前感谢您的任何建议。

【问题讨论】:

  • 如果我调用 test.php,则完全没有无论如何创建的文件
  • 查看 image.php 中&lt;?php 之前或?&gt; 之后的任何空格
  • 另外,如果你想确保它是动态的,你可能应该在 image.php 中防止 HTTP 缓存
  • 这是因为有 2 个空格,我以为我会检查一下,但是嗯 -.-,非常感谢
  • session_start(); 必须排在其他前面,就像“标题”一样

标签: php image dynamic


【解决方案1】:

您是否拥有 apache 上所有库的权限?你也在 image.php 文件上公开缓存

session_cache_limiter('public');

在文件的开头

【讨论】:

    【解决方案2】:

    在 test.php 中,您在一些输出后调用 session_start() - html 标记。

    会话无法开始。

    将 session_start 移动到 test.php 的顶部

    <?php
    session_start();
    ?>
    <html>
    ....
    some html code
    

    而且你不需要使用 echo 来输出 img 标签。您可以将其用作简单的 html。

    我猜你不明白 PHP 中的会话是如何工作的。我建议您阅读一些有关会话的文章。

    【讨论】:

    • 与会话问题无关是因为
    猜你喜欢
    • 2016-12-12
    • 2013-06-01
    • 2018-09-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多