How to give src to the

前端 未结 8 1573
抹茶落季
抹茶落季 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:44

    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

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

    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); ?>
    
    0 讨论(0)
提交回复
热议问题