javascript 使用文件对话框获取客户端文件的完整文件路径

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13976338/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-26 20:22:03  来源:igfitidea点击:

Getting full file path of a clients file using a file dialog box

javascriptjquery

提问by AnchovyLegend

I am trying to allow users to upload pictures to the server.

我正在尝试允许用户将图片上传到服务器。

I am trying to create a similar system to any website that has an 'attach' file or 'upload image' feature. All I need is to get the full path of the file select by the file dialog.

我正在尝试为任何具有“附加”文件或“上传图像”功能的网站创建一个类似的系统。我只需要通过文件对话框获取文件选择的完整路径。

I tried using this for the file dialog with no success:

我尝试将其用于文件对话框,但没有成功:

<input type="file">

This method does not provide the full file path, due to security reasons. My question is how can I create a similar input dialog to websites like tinypic, photobucket, etc.. that can help users input the full file path of a given image, into an input field?

由于安全原因,此方法不提供完整的文件路径。我的问题是如何为 tinypic、photobucket 等网站创建类似的输入对话框,以帮助用户将给定图像的完整文件路径输入到输入字段中?

I am aware that this cannot be done using the method above for security reasons, however, I have seen this done before on various websites without any problems, I was wondering what I had to do to implement a similar file dialog that helps fill in the text, which is a full file path, of an input field?

我知道出于安全原因无法使用上述方法完成此操作,但是,我之前在各种网站上看到过这样做没有任何问题,我想知道我必须做些什么来实现类似的文件对话框,以帮助填写输入字段的完整文件路径的文本?

采纳答案by closure

It is not possible to get the file full path on local machine using browser and javascript.

无法使用浏览器和 javascript 在本地计算机上获取文件完整路径。

However, as you would like to upload the file to the server, the easy possibility I see is to use html form with input type file. You will receive the file on your http server when the form is submitted.

但是,由于您想将文件上传到服务器,我看到的最简单的方法是使用带有 .html 的 html 表单input type file。提交表单后,您将在 http 服务器上收到该文件。

Here is a very good url http://www.cs.tut.fi/~jkorpela/forms/file.htmlthat explains the whole process nicely.

这是一个非常好的 url http://www.cs.tut.fi/~jkorpela/forms/file.html,它很好地解释了整个过程。