本文介绍了在javascript中获取文件大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

给出一个文件的路径,如:

C:\ file.jpg

如何在javascript中获取文件的大小?

given a path of a file like:
C:\file.jpg
how can i get the size of the file in javascript?

推荐答案

如果它不是由具有完全访问权限的JavaScript驱动的本地应用程序,则无法从路径名获取任何文件的大小。出于安全原因,运行javascript的网页无法访问本地文件系统。

If it's not a local application powered by JavaScript with full access permissions, you can't get the size of any file just from the path name. Web pages running javascript do not have access to the local filesystem for security reasons.

您可以使用优雅的降级文件上传器,例如如果要显示进度条。 HTML5还有,但目前还没有广泛支持。如果用户为输入[type = file] 元素选择文件,则可以从文件中获取有关该文件的详细信息集合:

You can use a graceful degrading file uploader like SWFUpload if you want to show a progress bar. HTML5 also has the File API, but that is not widely supported just yet. If a user selects the file for an input[type=file] element, you can get details about the file from the files collection:

alert(myInp.files[0].size);

这篇关于在javascript中获取文件大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:20
查看更多