开发者

Proper way to handle uploads using AJAX form

I'm using Valum's AJAX uploader, which is quite nice. I have a form that lets you fill out some info and optionally attach files.

I have a hidden input on the form that has a randomly generated "token" (5 character alnum). The uploads are sent to a tmp folder and the info about those files (name, dir, token) are kept in a uploads_tmp table in a database.

Then, when the user successfully submits the form, those files are moved to a more permanent location and the rows from the uploads_tmp are moved to the uploads table.

If the user submits and there are errors with the form, my script knows there ar开发者_如何学运维e uploads from a previous attempt via the token. So there's no need to re-upload files.

Is this the right way of doing it or am I going about it all wrong? I'm using PHP (CodeIgniter to be exact).


There isn't any one correct way of doing something like this. Your method seems like a good intuitive one, but really it's down to whatever works for you and your situation.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜