0

How to set img src for images that are only downloadable?

I have created donwload.php for image downloading using link.

I have set an access restriction on images, so images will be only accessible through download.php.

I want to use this image in img tag like this.

<img src="donwload.php?url=images/something.jpg" />

But this is not working. Please help me on this.

Community
  • 1
  • 1
Sanky
  • 367
  • 2
  • 6
  • 14
  • I guess you can't - if you change mimetype to application/octet-stream - browser don't know what format is the image and can't display it. – Andy Dec 31 '13 at 11:24
  • Have you set mime types in headers to "image/jpeg" ? – Lex Dec 31 '13 at 11:26

1 Answers1

1

First, you can't really prevent anyone from right-clicking an image and selecting "Save Image As…". ;-)

Your problem is easily solvable though. Embed your images as usual and wrap those you want to be downloadable with <a> tags point to your download.php file:

<a href="download.php?url=images/something.jpg" target="_blank">
    <img src="images/something.jpg" />
</a>
nietonfir
  • 4,697
  • 6
  • 29
  • 43