【问题标题】:Displaying image outside of web root not working , why?在网络根目录之外显示图像不起作用,为什么?
【发布时间】:2019-02-17 18:01:19
【问题描述】:

我刚刚了解了"how to add image outside of web root"。我已经完成了上面提到的所有事情。但是图像没有显示。这是名为get_image.php 的文件中的代码。和目录结构:

home.php

`...
<body>
   <img src="/get_image.php?image=myimg.jpg" width="100" height="100"/>
</body
...`

我检查了is_readable()file_exists() 似乎没问题。

app
  |_upload_dir
      |_myimg.jpg
      |_ myimg2.png
Public_html
  |_asset_dir
  |_get_image.php
  |_ home.php

get_image.php

<?php
  $mime_type = mime_content_type("../app/upload_dir/{$_GET['image']}");
  header('Content-Type: '.$mime_type);

  readfile("../app/upload_dir/{$_GET['image']}");
?>

那为什么图片不显示??

【问题讨论】:

  • 错误是什么?
  • 没有错误。只是一张破损的图片:(@Quasimodo'sclone
  • 显示错误日志或开启错误显示stackoverflow.com/tags/php/info
  • upload_dir 中的图片是永久的吗?这不是当前上传的临时目录?
  • upload_dir 是永久的@Quasimodo'sclone

标签: php apache


【解决方案1】:

问题解决了:)。好吧...我忘记了include 一个文件,该文件具有IMAGE_PATH 常量,该常量保存了upload_dir 的路径。

【讨论】:

    猜你喜欢
    • 2017-03-16
    • 1970-01-01
    • 2020-06-07
    • 2017-10-09
    • 1970-01-01
    • 1970-01-01
    • 2014-12-18
    • 1970-01-01
    • 2011-05-21
    相关资源
    最近更新 更多