在javascript中获取上传文件的数据 [英] get the data of uploaded file in javascript
问题描述
我想上传一个 csv 文件并处理该文件中的数据.这样做的最佳方法是什么?我不喜欢使用 php 脚本.我做了以下步骤.但是这个方法只返回文件名而不是文件路径.所以我没有得到想要的输出.
那么我如何获取该文件中的数据?
您可以使用新的 HTML 5 文件 api 读取文件内容
https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications>
但这不适用于所有浏览器,因此您可能需要服务器端回退.
I want to upload a csv file and process the data inside that file. What is the best method to do so? I prefer not to use php script. I did the following steps. But this method only returns the file name instead of file path.So i didnt get the desired output.
<form id='importPfForm'>
<input type='file' name='datafile' size='20'>
<input type='button' value='IMPORT' onclick='importPortfolioFunction()'/>
</form>
function importPortfolioFunction( arg ) {
var f = document.getElementById( 'importPfForm' );
var fileName= f.datafile.value;
}
So how can i get the data inside that file?
you can use the new HTML 5 file api to read file contents
https://developer.mozilla.org/en-US/docs/Using_files_from_web_applications
but this won't work on every browser so you probably need a server side fallback.
这篇关于在javascript中获取上传文件的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!