0

I am trying to download a file on image click using following code -

<a href="file:///D:\dir\a.pdf" target="_self" download>
  <i class="glyphicon glyphicon-download-alt" id="download">     </i>
</a>

If I add any html url, it's working fine but here it dosen't do anything. Please help

[EDIT]

I have even tried -

<a href="file:///D:/dir/a.pdf" target="_self" download>
      <i class="glyphicon glyphicon-download-alt" id="download">     </i>
    </a>
Ankur Rai
  • 297
  • 1
  • 5
  • 19

1 Answers1

0

Using file:///... will only work if your HTML page is also local (opened via file:/// also). If that is not the case look at: http://www.websina.com/bugzero/kb/browser-file-url.html

A Person
  • 1,062
  • 9
  • 17
  • Ok. Open your target file in the browser. Copy the path from the adress bar and paste it instead of the path you are using now. Is there a difference? – A Person Apr 18 '17 at 11:44
  • One more thing: This will only work if your HTML page is also local (opened via file:/// also). – A Person Apr 18 '17 at 11:50
  • html page is running through a mvc project with a different path. So its searching the file from path - localhost:45678/Admin/D:/dir/a.pdf.... and not in D:/dir/a.pdf... Can you suggest anything for this. – Ankur Rai Apr 18 '17 at 11:53
  • I'll add a link to my answer for this case. – A Person Apr 18 '17 at 11:58
  • best approach would be serve the file you want to download via a php or any other server side language you use. This can minimize your security risks and give you full control over what needs to be done. [This link](http://www.web-development-blog.com/archives/php-download-file-script/) has a good tutorial on that. – CodeMonkey Apr 18 '17 at 12:06
  • Yes. If he can access the files from his local server this is the preferred way. – A Person Apr 18 '17 at 12:24