How to open local file in browser

后端 未结 4 1209
不思量自难忘°
不思量自难忘° 2020-12-11 03:52

Website has tag, where href is path to local file. For example, Link. It doesn\'t work.

How to do it right? :)

相关标签:
4条回答
  • 2020-12-11 04:26

    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;
    }
    ?>
    
    0 讨论(0)
  • 2020-12-11 04:40

    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.

    0 讨论(0)
  • 2020-12-11 04:40

    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>
    
    0 讨论(0)
  • 2020-12-11 04:43

    Use a file URI.

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

    file:///D:/test.txt
    

    See also:

    • IEBlog: File URIs in Windows
    0 讨论(0)
提交回复
热议问题