php/ajax文件上传过程?
我想知道处理这个过程的最佳工作流程是什么。
基本步骤是。
用户选择一个 csv 文件并上传。
然后根据一组规则检查 csv 文件。
如果 csv 文件无效 用户会看到无效的行。
用户可以选择终止上传或删除无效行。
如果 csv 文件有效,或者单击了 strip 用户将看到一个屏幕来选择文件名。
如果文件名已被使用,用户可以选择
a) 重命名文件(为其选择的名称)
b) 替换现有文件。
c) 将文件重命名为 filename_1 等
选择名称后,将在数据库中创建一个名为 (csv_filename) 的表;
然后将 csv 中的数据输入到表中。
文件已删除。
用户被带到显示文件数据的页面(来自表格)
我的问题是, 这一切都是通过ajax来完成的。 我如何处理报告我们正在处理的文件?
我不想在 ajax 响应中传回文件名,因为这太容易篡改。
我不想创建一个表来保存文件路径并传回 id,因为仅仅为此创建一个表似乎是一种浪费。
I am wondering what the best workflow would be to handle this process.
Basic steps are.
The user selects a csv file and uploads it.
The csv file is then checked against a set of rules.
If the csv file is invalid
The user is shown the rows that are invalid.
The user is given the choice to terminate the upload or, strip the invalid lines.
If the csv file is valid, or strip is clicked
The user is shown a screen to choose the filename.
If the filename is already taken the user is given the choice to
a) rename the file (to a name of their choosing)
b) replace existing file.
c) rename the file to filename_1 etc
When the name is chosen a table is created in the database called (csv_filename);
Then data from the csv is entered into the table.
The file is deleted.
The user is taken to a page showing the file data (from the table)
My issue is,
This is all run through ajax.
How do I handle reporting what file we are dealing with?
I dont want to pass back the filename in an ajax response as that is too easy to tamper with.
I dont want to create a table to hold the filepath and pass back an id, as it seems to be a waste to have a table for just this.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在第一步上传文件时,存在一些问题。它完成了,它有一个文件名,并且无法终止,因为它已经在那里了。一定是这样,否则你将如何分析它?
从用户的角度来看,您可以让它看起来就像它的工作方式一样,这可能就是您的意思。
无论如何,要报告您正在处理的文件,请将其存储在会话变量中。
There are some issues with this, when the file is uploaded in the first step. Its done, its got a file name, and it can't be terminated because its already there. It has to be, or how will you analyze it?
From the users perspective you can make it look like thats how its working, which maybe is what you meant.
Anyways, to report what file you're dealing with, store it in a session variable.