在javascript中获取上传文件的数据 [英] get the data of uploaded file in javascript

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

问题描述

我想上传一个 csv 文件并处理该文件中的数据.这样做的最佳方法是什么?我不喜欢使用 php 脚本.我做了以下步骤.但是这个方法只返回文件名而不是文件路径.所以我没有得到想要的输出.

<input type='file' name='datafile' size='20'><input type='button' value='IMPORT' onclick='importPortfolioFunction()'/></表单>函数 importPortfolioFunction( arg ) {var f = document.getElementById('importPfForm');var fileName= f.datafile.value;}

那么我如何获取该文件中的数据?

解决方案

您可以使用新的 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屋!

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