可以在javascript中上传文件的数据 [英] get the data of uploaded file in javascript
问题描述
我要上传CSV文件并处理文件中的数据。什么是这样做的最佳方法是什么?我preFER不使用PHP脚本。我做了以下的步骤。但这种方法只返回,而不是文件的文件名path.So我没有得到期望的输出。
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?
推荐答案
您可以使用新的HTML 5文件API来读取文件内容
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屋!