php 本地主机可以看到单独驱动器上的文件,但无法显示它

问题描述 投票:0回答:1
几天来我一直在用头撞墙试图解决这个问题。 构建一个仅在本地主机上运行的应用程序。 我使用的是 Windows 10,安装了 Apache 和 PHP 8.1,服务器在 C: 上的文件夹中运行。该应用程序用于上传和查看图像。

此时,我可以上传图像文件,将其保存到 D: 上的上传文件夹中,并创建一个缩略图版本,该版本也保存到 D: 上的缩略图文件夹中。 它还将文件名与一些其他信息一起保存到数据库中。 一切都很好。

我遇到问题的部分是显示图像。

    我知道这些文件存在,因为我可以在文件资源管理器中看到它们
  1. 以编程方式,我知道它们存在,因为我已经使用
  2. is_file("D:/imagefolder/image_file.jpg")
    file_exists("D:/imagefolder/image_file.jpg")
    ,甚至 
    @getimagesize("D:/imagefolder/image_file.jpg")
     进行了测试,它们都返回 true。
  3. 此时我正在测试后尝试做一个简单的
  4. <img src="D:/imagefolder/image_file.jpg">
    ,但是phpstorm说它找不到该文件并且不会显示在页面上。
我尝试修改 Apache 配置文件中的

<Directory>

 和 php.ini 文件中的 
open_basedir
,但这只会让事情变得更糟,所以我将它们恢复了。

如果有人对正在发生的事情或我可以尝试的事情有任何想法,我将不胜感激。 谢谢。

php html localhost
1个回答
0
投票
除非可以从互联网/网络访问该图像,否则无法使用 img html 标签显示图像。 您可以通过读取 PHP 中的文件、对其进行 base64 编码并使用以下方法来解决此问题:

<img src="data:{mimeType};{base64EncodedDataHere}" />
示例:

<img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAOEAAADhCAMAAAAJbSJIAAABC1BMVEX///9ugbYAAABofLNkebIxMTG0vNZme7PM0uNvg7psf7VfdbBugrf6+vmmpqbZ3evByN1gaYLGxsbj4+MUFBR1dXX5+v17e3tbX25HR0fj5vCfn59dY3Sjrs6zs7OsrKyZpcna2tpga4lqamonJydhYWF9jb3s7vNpeaFecZtSWW9YXGjDyt/v7+5RUVGUlJSJiYmlrMaVnrx/iq2LmcJqeqgwOE9SYIg8PDxJSUk6RGC+vr6gp7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