如何使用< img>中的src属性从另一个驱动器检索和显示图像标签? [英] How to retrieve and show images from another drive using src attribute in <img> tag?

查看:139
本文介绍了如何使用< img>中的src属性从另一个驱动器检索和显示图像标签?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

<img src="d:/Tulips.jpg" >
</img>

<img src="file:///d:Tulips.jpg">

如何使用中的src属性从另一个驱动器检索和显示图像< img> 标签?
如果图像位于相同的文件夹中,但是当图像的源位于另一个驱动器上时,它不起作用。

How to retrieve and show images from another drive using src attribute in <img> tag? If the image is in the same folder it works but when the source of the image is on another drive it's not working.

推荐答案

jpg除非从桌面或计算机打开文件系统,否则无法将文件系统路径放在 src 中。您可以尝试将该文件作为 base64 编码的字符串传递。我在PHP中展示了如何做到这一点,因为你用PHP标记了这个问题。

jpgYou can't put your file system path in the src unless you open it from your desktop or your computer. You can try to pass the file as base64 encoded strings. I'm showing how to do it in PHP because you tagged this question with PHP

$image = file_get_contents('d:/Tulips.jpg');

$image_codes = base64_encode($image);

然后在你的html里就这样。

And in your html put it like this.

<image src="data:image/jpg;charset=utf-8;base64,<?php echo $image_codes; ?>" />

这篇关于如何使用&lt; img&gt;中的src属性从另一个驱动器检索和显示图像标签?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆