How to give src to the

前端 未结 8 1572
抹茶落季
抹茶落季 2020-12-09 21:11

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

I have stored the image on my local drive.

How to achieve this?

Th

相关标签:
8条回答
  • 2020-12-09 21:37

    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" />
    
    0 讨论(0)
  • 2020-12-09 21:38

    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

    0 讨论(0)
  • 2020-12-09 21:40

    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.

    0 讨论(0)
  • 2020-12-09 21:40

    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 = $"data: image/png; base64,{base64ImageRepresentation}";
                                imgEvid.Attributes.Add("src", val);
                            }
    

    Hope this will help

    0 讨论(0)
  • 2020-12-09 21:42

    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.

    0 讨论(0)
  • 2020-12-09 21:42

    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

    0 讨论(0)
提交回复
热议问题