如何将SRC送给< img>系统驱动器中的HTML标记?

发布于 2025-02-11 20:48:28 字数 193 浏览 2 评论 0原文

我想使用html < img>标签在网页上显示图像。

我已经将图像存储在本地驱动器上。

如何实现这一目标?

代码:

<img src="D:\Images\TechnipLogo.jpg">

图像未显示。

I want to display an image on a web page using HTML <img> tag.

I have stored the image on my local drive.

How to achieve this?

The code:

<img src="D:\Images\TechnipLogo.jpg">

Image is not displayed.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(8

穿透光 2025-02-18 20:48:28

您必须使用PC中正确的本地路径和正确的驱动字母。然后更改backslashs()以向前斜杠(/),然后在路径之前添加文件:///,因此

<img src="D:\Images\TechnipLogo.jpg">

<img src="file:///D:/Images/TechnipLogo.jpg">

**也请注意,在Chrome和其他浏览器中,您可能无法使用本地未本地托管的站点上的文件/图像。请参考这篇文章:无法打开本地文件 - Chrome:不允许加载本地资源

You must use the correct local path from your PC and the correct Drive letter. Then change the backslashs () to forward slashes (/) and add file:/// before the path, so:

<img src="D:\Images\TechnipLogo.jpg">

becomes:

<img src="file:///D:/Images/TechnipLogo.jpg">

**Also, please note that in Chrome and possibly other browsers, you may not be able to use a local file/image on a site that is not locally hosted. Please reference this post: Cannot open local file - Chrome: Not allowed to load local resource

喜爱皱眉﹌ 2025-02-18 20:48:28

您要完成的工作是所有现代浏览器中都存在的安全功能。

只有在运行本地存储的HTML文件时,您才能做到这一点 - 将其部署到Web服务器后将无法工作。

如果您真的必须这样做,则可以构建浏览器扩展名 - Firefox扩展名和IE扩展名可以访问本地资源。但是,镀铬更具限制性。

What you are trying to accomplish is a security feature present in all modern browsers.

You could do that only if you run the html file stored locally - it will not work once you deploy it to a web server.

If you really MUST do that, you could build a browser extension - Firefox extensions and IE extensions can access local resources. Chrome is much more restrictive however.

岁月蹉跎了容颜 2025-02-18 20:48:28

您的图像应在相对路径上,而不是绝对的路径。

说您的HTML文件在D:\ myhtml \ home.html中。在MyHTML中复制图像文件夹。然后将代码更改为&lt; img src =“ Images \ Techniplogo.jpg” /&gt; < /code>。

希望这会有所帮助

Your image should be on a relative path not absolute one.

Say your html file is in D:\myhtml\home.html. Copy the Images folder in myhtml. Then change your code to <img src="Images\TechnipLogo.jpg" />.

Hope this helps

眼趣 2025-02-18 20:48:28

我想使用html

在网页中显示我的图像

如果您从网页显示图像,则图像文件必须仅在您的Web服务器上。
您无法从本地系统显示该文件,因为该文件仅从Web服务器显示。

I want to display my image in the web page using html

If you are showing the image from your web page, the image file has to be on your web server only.
You can not show it from your local system, as the file is Displayed from web server only.

浸婚纱 2025-02-18 20:48:28

当您在访问者中加载其浏览器在Internet中加载的网页时,

您的图像路径在IMG标签中只需指向thier filesystem localtion而不是您的文件
SystemLocation

您必须将IMG上传到网络服务器中,例如Apache或IIS或主机位置,并使用此公共图像路径设置IMG标签的路径,

以获取更多详细信息,您可以在Internet和Web中搜索客户端服务器概念

,但是如果您的意思是在浏览器中,则可以表明其与安全问题

有关

when you webpage loaded in visitors with their browsers in internet

your image path in img tag just point to thier filesystem localtion not your file
systemlocation

you must upload your img in your webserver like apache or iis or host location and set path of img tag with this public image path

for more detail you can search about client server concept in internet and web

but if you mean in your browser did not show its relate to security issues

be successfull

窝囊感情。 2025-02-18 20:48:28

您无法实现这一目标,否则您不应该实现这一目标。上传网站时,链接到计算机上的文件将无法工作。您应该将图像移至与index.html相同的文件夹中,或在与index.html相同的文件夹中制作一个文件夹,然后您可以像这样折叠文件:

<img src="Images\TechnipLogo.jpg" />

You can't achieve that, Or you shouldn't achieve that. Linking to files on your computer will not work when you upload the website. You should move the images into the same folder as your index.html or make a folder in the same folder as your index.html then you can refrence the file like this:

<img src="Images\TechnipLogo.jpg" />
岁吢 2025-02-18 20:48:28

好吧,由于不同的浏览器有很多问题,因此使用Apache Paths配置,我尝试了所有可能的方法文件:file:// c:c | |它们都没有在W7中的Firefox 57.0上使用,因此有一个快速解决方案(如果使用PHP)。只需使用此内容调用文件“ embedimg.php”:

  <?php

     $file = $_GET["imgg"];
     $type = 'image/jpeg'; // or whatsoever
     header('Content-Type:'.$type);
     header('Content-Length: ' . filesize($file));
     $img = file_get_contents($file);
     echo $img;

     exit();

 ?>  

从您的img标签中调用此“ embedimg.php”:

   <img src="embedIMG.php?imgg=THEPATHTOYOURIMAGE">

pathtoyourimage将是您映像的路径“ d:\ images \ techniplogo.jpg”,最好做到这一点。方式“ d:/images/techniplogo.jpg”,窗户上有常见的斜线。如果您的路径中有空格或特殊字符,则必须使用urlencode()函数声明它:

  <?php  $THEPATHTOYOURIMAGE=urlencode($THEPATHTOYOURIMAGE); ?>

Well, as there are many issues with different browsers and so with Apache paths config, I tried all the possible ways file: file:// c: c| and none of them worked on my Firefox 57.0 in W7, so there is a fast solution (if you use php). Just call a file "embedIMG.php" with this content:

  <?php

     $file = $_GET["imgg"];
     $type = 'image/jpeg'; // or whatsoever
     header('Content-Type:'.$type);
     header('Content-Length: ' . filesize($file));
     $img = file_get_contents($file);
     echo $img;

     exit();

 ?>  

Call this "embedIMG.php" from your img tag:

   <img src="embedIMG.php?imgg=THEPATHTOYOURIMAGE">

THEPATHTOYOURIMAGE will be the path to your image "D:\Images\TechnipLogo.jpg", it's better to do it this way "D:/Images/TechnipLogo.jpg" with common slashes on Windows. If you have spaces or special characters in your path you will have to declare it with urlencode() function:

  <?php  $THEPATHTOYOURIMAGE=urlencode($THEPATHTOYOURIMAGE); ?>
宛菡 2025-02-18 20:48:28

您可以查看我的答案。我已经使用C#语言解决了问题
=“ c:/localfile.jpg”&gt;?

<asp:Image ID="imgEvid" src="#" runat="server" Height="99px"/>
                        if (File.Exists(filepath))
                        {
                            byte[] imageArray = System.IO.File.ReadAllBytes(filepath);
                            string base64ImageRepresentation = Convert.ToBase64String(imageArray);
                            var val = $"data: image/png; base64,{base64ImageRepresentation}";
                            imgEvid.Attributes.Add("src", val);
                        }

希望这会有所帮助

You can look into my answer. I have resolved the issue using C# language
Why can't I do <img src="C:/localfile.jpg">?

<asp:Image ID="imgEvid" src="#" runat="server" Height="99px"/>
                        if (File.Exists(filepath))
                        {
                            byte[] imageArray = System.IO.File.ReadAllBytes(filepath);
                            string base64ImageRepresentation = Convert.ToBase64String(imageArray);
                            var val = 
quot;data: image/png; base64,{base64ImageRepresentation}";
                            imgEvid.Attributes.Add("src", val);
                        }

Hope this will help

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文