Open local file from browser

4

Hello,

What is the most correct way to open a local file (shared drive via network) through the browser? The file must be opened through a local application (desktop) previously installed on the PC. Example: Link to an excel file, when click should open the file in Excel (Program)

<a href="file:///C:\Users\jsantos1991\Desktop\Teste.xlsx">Excel</a>

The issue is that in this way the window asks if you want to open or save and if you choose the save option, it generates a copy of the file.

How can I open through the local application?

AccordingtomyresearchwhatIneedisaURIschemems-excel:

HoweverIcanopenthewindowtostarttheapplicationbutthenitgeneratesthefollowingerror:

Thank you

    
asked by anonymous 21.05.2018 / 08:53

2 answers

2

The "right" form is relative, depending on the language you are using.

For example, if you want to use html5, you can use the following code as part of the upload feature:

<input type="file" name="arquivos" class="btn btn-success"/>

Remembering that this input just loads information from where the file is on the user's machine, you still need to upload / send that file to the server if that's what you want.

If you can not use html5, but are using some web framework (like java with JSF, Struts, Spring ...) you can use some framework scriptlet.

If you want to do without a supporting server language, you can search for file upload scripts in javascript with or without jquery (javascript file upload / jquery file upload).

    
21.05.2018 / 13:57
2

You need to use the protocol file:/// (yes, it's three slashes) if you want to link to local files.

<a href="file:///C:\Programs\sort.mw"> Link 1 </a>
<a href="file:///C:\Videos\lecture.mp4"> Link 2 </a>

These will never open the file in your local applications automatically .

  

This is for security reasons, and I'll get to that in the last   section. If it opens, it will only open in the browser. If your   browser can display the file, it will. If you can not, probably   will ask if you want to download.

     

Some browsers, like modern versions of Chrome, refuse to   pass from the http protocol to the file protocol. Therefore, it is   best to open this file locally using the file protocol,   if you want to do these things.

Why does he get stuck without file: /// ?

  

The first part of a URL is the protocol. A protocol is some letters, then two points and two bars. HTTP:// and FTP:// are valid protocols; C:/ is not and I'm sure not even   looks like one.

     

C:/ is also not a valid web address. The browser can   assume that it must be http://c/ with a blank port   specified, but this will fail.

     

Your browser may not assume that you are referring to a file   local. There are few reasons to make this assumption, because the websites   generally do not attempt to link to the local files of the   people.

     

So, if you want to access local files: say to use the   file protocol.

Why three bars?

  

Because it's part of the File URI scheme. You have the option to   specify a host after the first two slashes. If you ignore the   specification of a host, it will only assume that you are   referring to a file on your own PC. In other words: file:///C:/ etc is a shortcut to file:// localhost/C:/etc .

These files will still open in your browser and that's good

  

Your browser will respond to these files in the same way that they   responded to the same file anywhere on the Internet. Those    files will not be opened in your default file handler   (for example, MS Word or VLC Media Player), and you can not   do nothing like asking File Explorer to open the location of the   file.

This is extremely good for your security.

  

Sites in your browser can not interact with your system   very well. If a good website could say talk.mp4 to   open in VLC.exe, a malicious website could tell you to   open virus.bat in CMD.exe. Or you can just tell your PC to   run some Uninstall.exe files, or open the File Explorer one   million times.

     

This may not be convenient for you, but HTML and   browser was not really designed for what you are doing. If   If you want to open lecture.mp4 in VLC.exe, consider writing a   desktop application.

    
29.05.2018 / 18:09