8

Website has tag, where href is path to local file. For example, <a href="D:\test.txt">Link</a>. It doesn't work.

How to do it right? :) It must work in IE only, other browsers are not necessary

asked Mar 20, 2014 at 13:55

4 Answers 4

7

Here you need to use a "file" protocol to link a file in the HTML like,

<a href="file:///D:\test.txt">Link</a>

The browser may or may not open the file due to the security setting. You can click the right button and choose "copy link address" and then paste it into the browser.

answered Feb 23, 2015 at 4:32
Sign up to request clarification or add additional context in comments.

Comments

3

I came across the same problem and looked for a solution but couldn't find anything, file:// was saying not allowed to open local file and this wouldn't be possible to work

May not solve it for everybody but I did a workaround in php using file_get_contents(). It's a function in php that gets the text content of a file and puts it into a variable - which does allow you to access local files on a network.

So you just make a php file that takes the id or string of the file and pulls the data and use php to put it onto the screen so as far as the browser is concerned its a hosted file

<a href='getContents.php?id=5'>

getContents.php

<?php
$id = $_GET['id'];
if(ctype_alnum($id)){//
//get file name from Database
$data[5]['file_path'] = 'file.htm';
$page = file_get_contents('//server//'.$data[$id]['file_path']);
echo $page;
}
?>
answered Feb 1, 2015 at 22:03

1 Comment

You should also set the Content-Type header if the file is something other than HTML
2

Use a file URI.

Can’t test it (have no Windows/IE), but it should be:

file:///D:/test.txt

See also:

answered Mar 21, 2014 at 14:07

Comments

1

if you want to open the files local with the default program, than you can check my url protocol https://github.com/berti92/FileBridge

Install it and create a link with the url protocol

<a href="filebridge:PASTE HERE THE PATH">Open me</a>
answered Feb 25, 2015 at 22:48

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.