Html 从 Firefox (file:///) 打开硬盘驱动器上的直接文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2148584/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Open a direct file on the hard drive from firefox (file:///)
提问by aviv
I have a small php system i created for myself. This system contains a few .doc and .docx file documents. I want to be able to open them directly from the browser and not downloading them.
我有一个为自己创建的小型 php 系统。该系统包含一些 .doc 和 .docx 文件文档。我希望能够直接从浏览器打开它们而不是下载它们。
I created a link:
<a href="file:///c:/mysite/myfile.docx">myfile</a>
But FireFox does not open the link. While href="http://localhost/myfile.docx"
works fine - it offers me to download the file.
我创建了一个链接:
<a href="file:///c:/mysite/myfile.docx">myfile</a>
但 FireFox 没有打开该链接。虽然href="http://localhost/myfile.docx"
工作正常 - 它让我下载文件。
Any ideas how can i do it? Maybe change something in firfox options / security settings? And if you are at it, is there any chance to do it in IE8?
任何想法我该怎么做?也许更改 firfox 选项/安全设置中的某些内容?如果您愿意,是否有机会在 IE8 中做到这一点?
Thanks.
谢谢。
采纳答案by aviv
Although i still think it is a programming question, it was answered here: https://superuser.com/questions/103026/open-a-direct-file-on-the-hard-drive-from-firefox-file
虽然我仍然认为这是一个编程问题,但在这里得到了回答:https: //superuser.com/questions/103026/open-a-direct-file-on-the-hard-drive-from-firefox-file
Both Firefox and IE8 support the File URI scheme.
Firefox 和 IE8 都支持文件 URI 方案。
Here are some examples valid for Windows systems, referring to the same file c:\WINDOWS\clock.avi
file://localhost/c|/WINDOWS/clock.avi
file:///c|/WINDOWS/clock.avi
file://localhost/c:/WINDOWS/clock.avi
file:///c:/WINDOWS/clock.aviWhile the last is the most obvious and human-readable, the first one is the most complete and correct one.
以下是一些适用于 Windows 系统的示例,引用相同的文件 c:\WINDOWS\clock.avi
file://localhost/c|/WINDOWS/clock.avi
file:///c|/WINDOWS/clock.avi
file://localhost/c:/WINDOWS/clock.avi
file:///c:/WINDOWS /clock.avi虽然最后一个是最明显和人类可读的,但第一个是最完整和正确的。
Apparently (from the same url):
显然(来自同一个网址):
Mozilla browsers refuse to follow file URLs on a page that it has fetched with the HTTP protocol.
Mozilla 浏览器拒绝跟踪它使用 HTTP 协议获取的页面上的文件 URL。
but:
但:
Mozilla browsers can be configured to override this security restriction as detailed in Mozillazine's "Links to Local Pages Don't Work".
Mozilla 浏览器可以配置为覆盖此安全限制,如 Mozillazine 的“本地页面链接不起作用”中所述。
回答by Pekka
Access to local files in Firefox can't be done unfortunately due to security restrictions. As far as I know (I have asked here repeated times myself) it's not even possible to allow select sites through a configuration setting or similar.
遗憾的是,由于安全限制,无法访问 Firefox 中的本地文件。据我所知(我自己在这里反复询问过)甚至不可能通过配置设置或类似设置来允许选择站点。
There is a workaround (ponentially unsafe and to be handled with care), you could register a custom protocol as outlined in this question.
有一个解决方法(部分不安全,需要小心处理),您可以注册一个自定义协议,如本问题所述。
回答by Chetan Aher
I used symlink for windows added that file to my resources folder by creating symlink. How to create symlink shown here for windows http://www.sevenforums.com/tutorials/278262-mklink-create-use-links-windows.html
我使用 Windows 符号链接通过创建符号链接将该文件添加到我的资源文件夹中。如何为 Windows 创建此处显示的符号链接 http://www.sevenforums.com/tutorials/278262-mklink-create-use-links-windows.html
That worked for me while same problem. Cheers!
这对我有用,而同样的问题。干杯!
回答by BalusC
Which syntax did you use? The correct syntax for e.g. Edit:not relevant anymore as OP has edited his question to include the syntax.c:/path/to/file.ext
would have been file:///c:/path/to/file.ext
.
您使用了哪种语法?eg 的正确语法编辑:不再相关,因为 OP 编辑了他的问题以包含语法。c:/path/to/file.ext
应该是file:///c:/path/to/file.ext
.
Note that this doesn't work at all if the file is stored at the server machine which in turn is a physically differentmachine than the client machine (where the webbrowser runs).
请注意,如果文件存储在服务器计算机上,而服务器计算机与客户端计算机(运行网络浏览器的计算机)在物理上不同,则这根本不起作用。
回答by Dzeimsas Zvirblis
Security restrictions are a big issue when trying to access a file outside of your project. What I would recommend (if you are using IIS 7+), is to create a virtual directory to the folder that contains your docs on your C drive. Then you can access your files from the C drive by using the VP name and the host/localhost will be included in your url rather than the "file:///"
.
尝试访问项目外的文件时,安全限制是一个大问题。我建议(如果您使用的是 IIS 7+)是在 C 驱动器上为包含文档的文件夹创建一个虚拟目录。然后,您可以使用 VP 名称从 C 驱动器访问您的文件,并且主机/本地主机将包含在您的 url 中而不是"file:///"
.
However, if you are using IIS Express, you will have to manually add the virtual directory by updating the "applicationhost.config"
file. Take a look at this link for more detail on how to set that up.
但是,如果您使用的是 IIS Express,则必须通过更新"applicationhost.config"
文件来手动添加虚拟目录。有关如何设置的更多详细信息,请查看此链接。
http://bhagirath-j-patel.blogspot.com/
http://bhagirath-j-patel.blogspot.com/
Hope this helps.
希望这可以帮助。
回答by humer
My working code to open locally uploaded Files via Firefox (51.0) and the actual Internet Explorer (11).
我的工作代码通过 Firefox (51.0) 和实际的 Internet Explorer (11) 打开本地上传的文件。
$pfad = trim(strip_tags(stripslashes(urldecode($_REQUEST['pfad']))));
$datei = trim(strip_tags(stripslashes(urldecode($_REQUEST['file']))));
exec ('start c:\WINDOWS\system32\explorer.exe /select /seperate /n, /e, '.str_replace('/','\',$pfad).utf8_decode($datei));
saved as open.php
保存为 open.php
"pfad" is a path BELOW the local Webroot (in my case customer folder) while "file" is - of course - the file which I want to open.
“pfad”是本地Webroot(在我的情况下为客户文件夹)下方的路径,而“file”当然是我想打开的文件。
I call it like so: ...href="open.php?pfad=<my_path>&file=<the_file>"
我这样称呼它: ...href="open.php?pfad=<my_path>&file=<the_file>"
where both parameters are urlencoded
其中两个参数都经过 urlencoded