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

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

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.

Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126
shwe45
  • 13
  • 1
  • 2
  • 2
    Show us what you've tried and give examples of it working and not working. – Jeff Apr 04 '14 at 06:44
  • then it will show the image, but when i place my image in another drive and it s not showing anything – shwe45 Apr 04 '14 at 06:49

3 Answers3

5

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);

And in your html put it like this.

<image src="data:image/jpg;charset=utf-8;base64,<?php echo $image_codes; ?>" />
iamsleepy
  • 550
  • 3
  • 7
  • Thnk u for u answers....But it not showing image , it showing some code like this data:image/jpg;base64, /9j/4AAQSkZJRgABAgEAYABgAAD/4RKGRXhpZgAATU0AKgAAAAgABwEyAAIAAAAUAAAAYkdGAAMAAAABAAQAAEdJAAMAAAABAD8AAIKYAAIAAAAWAAAAdpydAAEAAAAcAAAAAOocAAcAAAfSAAAAAIdpAAQAAAABA – shwe45 Apr 04 '14 at 07:07
  • @shwe45, Btw, am just curious why you want to read it from disk ? It will definitely wont work when you are moving it to a **live** server as you know all the paths will become _invalid_ – Shankar Narayana Damodaran Apr 04 '14 at 07:17
  • i am working on one project, it is fully based on images uploading and many things, that whole project i am putting in C folder, but i feel that images are not safe there. i stored all uploaded images to another folder then, i got problem in displaying images.. – shwe45 Apr 04 '14 at 07:21
  • 1
    Nah, why don't you create an `image upload` folder where you are running the script from ? If you are worried about the _security_ of your images , then you can use `.htaccess` to restrict direct access to your image folder. – Shankar Narayana Damodaran Apr 04 '14 at 07:24
  • i created folder yr thats not the problem. but when my c folder is crashed, or damaged then i would loss users images. that is the problem – shwe45 Apr 04 '14 at 07:28
  • 2
    I think what @ShankarDamodaran suggested was better. If you are worried of crashing disk. You can try to use `RAID` but expensive. Or you can upload to both your webroot as the primary storage and `d:` as backup. I've edited my answer. Should work now. – iamsleepy Apr 04 '14 at 07:33
  • No problem. ;). But think about what was suggested ok. – iamsleepy Apr 04 '14 at 07:52
1

Try

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

You were missing a slash after your drive lettter.

stealthyninja
  • 10,343
  • 11
  • 51
  • 59
0

The reason is you are doing the inevitable.

HTML markups cannot read data from the local disk drives, you need to put them in a folder or access it from the same directory for this to work.

Since, when you publish your website images are to be accessed from the folders of your webserver, accessing from a hard-drive directly (not possible via HTML though) puts you under potential risks.

Community
  • 1
  • 1
Shankar Narayana Damodaran
  • 68,075
  • 43
  • 96
  • 126