【问题标题】:php does not serve an image to html?php 不向 html 提供图像?
【发布时间】:2013-11-11 20:19:47
【问题描述】:

我正在尝试通过 php 脚本将图像提供给 html。但我被卡住了,它不工作:-( 下面是我的 image.php 脚本

<?
    $_GET['f'] = 'all_three.jpg';
$image = null;
$image = file_get_contents($_GET['f']);
    header("Content-Type: image/jpeg");
    echo $image;
?>

下面是我的 index.html

    <html>
    <head>
       <meta content="text/html;charset=utf-8" http-equiv="Content-Type">
       <meta content="utf-8" http-equiv="encoding">
       <title>Page Title</title>
    </head>
    <body>
       <img src="image.php" alt="Image" />
    </body>
   </html>

图像链接在 php 中是“硬编码”的,我所做的只是调用“image.php”来提供该硬编码图像,但它不起作用!我做错了什么?

【问题讨论】:

  • 您遇到了什么错误?你有正确的路径名吗?图片真的存在吗?
  • 您是否尝试过直接访问 image.php 以查看它是否按预期工作或显示一些错误?
  • index.html,image.php, all_three.jpg 在我的 htdocs/testwebsite/ 中
  • 当你尝试直接打开图片url时会发生什么?您还可以使用浏览器的调试工具查看图像的 http 请求,看看发生了什么。
  • @user2959229 我尝试直接访问“image.php”,它是一个空白页面。

标签: php html image


【解决方案1】:

当我查看->加载 image.php 后的源代码时,我可以看到 php 脚本

任一:

您依赖于short tags,但您的服务器配置为不支持它们。

不推荐使用,停止使用。使用&lt;?php 而不是&lt;?

或者:

您的服务器不支持 PHP。在上面安装 PHP。

【讨论】:

    【解决方案2】:

    错误在于内容编码,您使用的是什么文本编辑器?记事本 6.x ?
    如果是,请尝试:

    Encoding > Encode in UTF-8 without BOM
    

    BOM 使 php 文件具有更多内容并且图像不接受其他内容其他图像

    【讨论】:

      猜你喜欢
      • 2020-06-30
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多