如何在上传到服务器之前预处理本地CSV文件? [英] How to preprocess a local CSV file before uploading to a server?

查看:218
本文介绍了如何在上传到服务器之前预处理本地CSV文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试设置一个网页,受信任的用户可以上传本地CSV文件,这些文件将被用户解析,验证,审核,然后插入到MySQL数据库的各个表中。

I am trying to set up a web page where trusted users can upload local CSV files that will be parsed, validated, reviewed by the users, and then inserted into various tables on a MySQL database.

网站的其余部分是使用PHP和jQuery编写的。我知道如何将CSV文件读入PHP并生成查询。问题是文件的验证和解析是交互式的 - 需要向用户询问有关数据的各种信息,将文件中的列与数据库中的字段匹配,并有机会查看和更新回答,直到他们确定一切正确。

The rest of the site is written using PHP and jQuery. I know how to read a CSV file into PHP and generate a query. The problem is that the validation and parsing of the file is interactive-- the user needs to be asked for various information about the data, match up columns from the file with fields in the database, and be given the opportunity to review and update their answers until they're sure everything is correct.

每次用户更改内容时重新加载整个页面似乎都是1990年的,所以我认为AJAX将是在客户端执行此操作的方法,但似乎浏览器出于安全原因特别禁止打开本地文件。

It seems kind of 1990's to reload the whole page every time the user changes something, so I assumed that AJAX would be the way to do it client-side, but it seems that opening local files is specifically prevented by browsers for "security reasons".

是否存在一种普遍接受的安全有效地让用户做出决策的模式在将文件实际上传到服务器之前的文件内容?或者人们真的只是在这种情况下发送了几十个POST请求?

Is there a generally accepted pattern for securely and efficiently letting a user make decisions based on the contents of a file before actually uploading the file to the server? Or do people really just send dozens of POST requests in such situations?

顺便说一句,我们不使用Windows或任何封闭源代码,所以不幸的是解决方案不能依赖在Internet Explorer或ActiveX上。

By the way, we do not use Windows or anything closed-source, so unfortunately the solution cannot rely on Internet Explorer or ActiveX.

谢谢。

推荐答案

你不要如果您使用从firefox 3.6和Chrome 7开始提供的javascript FileReader API,则需要向服务器发出任何请求。幸运的是,存在非常有趣的文章,可以很清楚地解释API的工作原理。

You don't need to make any request to the server if you use the javascript FileReader API available starting from firefox 3.6 and Chrome 7. Fortunately really interesting articles exist that explain quite clearly how the API works.

http://www.html5rocks.com/en/tutorials/file / dndfiles /

如果您对不同浏览器中对API的支持有疑虑,请在其他文章的末尾显示:

If you have concerns about the support for the API in the different browsers it is displayed at the end of this other article:

https://developer.mozilla.org/en / DOM / FileReader

我最近使用此API上传文本和二进制文件,如果您决定尝试它并且有任何疑问,请随时回复我。

I've recently used this API for uploading both text and binary files so don't hesitate to get back to me if you decide you want to try it and you have any doubt.

这篇关于如何在上传到服务器之前预处理本地CSV文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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