HTML5文件和FileLists路径 [英] HTML5 Files and FileLists path

查看:96
本文介绍了HTML5文件和FileLists路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用了Webkit DevTools,并得到了这个结果:



$ p $文件列表$ b $ 0文件
文件名:script.js
文件大小:71268
名称: script.js
大小:71268
类型:application / x-javascript
__proto__:文件
长度:1
__proto__:FileList

文件名,大小和类型在那里(任何人知道为什么名称和大小有2个变量),但路径是不是。

有什么办法可以找到这个文件的路径,如果没有,浏览器和javascript如何读取这个文件(比如POST方法&确定类型和大小)?

解决方案

正如你可以在 WHATWG HTML spec


[f]或历史原因,
IDL属性在文件名
前加字符串C:\ fakepath \。一些
遗留用户代理实际上包含了
的完整路径(这是一个安全性
漏洞)。



<阅读 MDC ,我们可以看到,Mozilla的文件执行对象有一个名为 mozFullPath 的(非标准)属性,包含


[t ]引用
文件的完整路径;只能用
代码
中的UniversalFileRead权限。

该页面还解答了有关冗余File对象中的数据:属性 fileName fileSize 已被弃用。另请参阅W3C的文件API工作草案,其中未提及这些文件。 b

回答你的问题的第二部分:


如果不是,那么浏览器和
JavaScript读取文件(例如POST
方法&确定类型和
大小)?

当然,在内部可以访问完整的文件路径(并在多个向用户显示的浏览器中),但是不能在网页中运行的JavaScript脚本访问。



顺便说一下,几年前,在这方面有一个讨论 WHATWG邮件列表


I am wondering where the file path is stored in a File object in HTML javascript.

I used the Webkit DevTools and got this:

FileList
0: File
    fileName: "script.js"
    fileSize: 71268
    name: "script.js"
    size: 71268
    type: "application/x-javascript"
    __proto__: File
length: 1
__proto__: FileList

The file name, size and types are there(anyone knows why name and size have 2 variables), but the path is not.

Is there any way to find path of the file, and if not, how does the browser and javascript read the file(such as POST methods & determining the type and size)?

解决方案

As you can read in the WHATWG HTML spec,

[f]or historical reasons, the value IDL attribute prefixes the filename with the string "C:\fakepath\". Some legacy user agents actually included the full path (which was a security vulnerability).

Reading on on MDC, we can see that Mozilla's implementation of the File object has a (non-standard) property named mozFullPath, containing

[t]he full path of the referenced file; available only to code with UniversalFileRead privileges in chrome.

That page also answers your question about the redundant data in the File object: properties fileName and fileSize are deprecated. Also look at W3C's File API Working Draft, where those are not mentioned.

To answer the second part of your question:

if not, how does the browser and JavaScript read the file (such as POST methods & determining the type and size)?

Of course, internally the complete file path can be accessed (and is in several browsers shown to the user), but it's not accessible to JavaScript scripts running in a web page.

By the way, a few years ago there was a discussion about this on the WHATWG mailing list.

这篇关于HTML5文件和FileLists路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆