PHP jQuery的阿贾克斯()文件上传服务器端的理解 [英] PHP jQuery .ajax() file upload server side understanding
问题描述
我有一个HTML形成previously仅用于为用户文本属性,这是所有使用AJAX通过URL来调用PHP控制器的功能,通过数据库和服务器端调用(删节版),以刷新页面内容
I have an HTML form that previously was only used for text attributes for users, that was all using AJAX to call a PHP controller functions via URLs to refresh page content via database and server-side calls (abridged version)
<input type="text" id="firstname" name="FIRSTNAME"/>
<input type="text" id="lastname" name="LASTNAME"/>
<input name="Submit"type="submit" value="Submit" />
这创建用户的形式现在需要将文件上传机制,用户图像
This "create user" form now needs to incorporate a file uploading mechanism, for user images
<input type="file" name="userImage" />
问题是,窗体被通过 .serialize
提交的阿贾克斯
#create表单提交
The problem is that the form is being submitted via .serialize
in the .ajax
#create form submit
$.ajax({
url: 'controller.php?command=create',
type: 'POST',
data: $( form ).serialize(),
创建URL调用PHP控制器回声$ dmv-&GT;创建();
,这是模型公共函数来创建(){/ /执行数据库插入并执行
我已阅读,连载没有意义的文件,这是事实,但我也想尝试找出如何更新我现有的形式将文件上传功能,它
I have read that serialize does not make sense for files, which is true, but I also want to try to figure out how to update my existing form to incorporate file upload functionality to it
我试图理解 jquery.form.js
插件(的 http://malsup.com/jquery/form/#file-upload ),但不知道如何将其结合在一起。
I have tried to understand the jquery.form.js
plugin ( http://malsup.com/jquery/form/#file-upload ) but cannot understand how to tie it all together.
我相信什么,我需要做的是有一个单独的逻辑文件上传执行,再配合背部与文件名原来的逻辑,这是文件存储与记录,而不是在存储于数据库中的唯一的映像名称BLOB图像存储。
I believe what I need to do is have the file upload execute as a separate logic, then tie back with the original logic for file name , this is file storage with the unique image name stored in the database under the record, not BLOB image storage.
让我知道如果我能提供任何进一步的信息,并且由于可以给予任何帮助。
Let me know if I can provide any further info, and thanks to any help that can be given.
推荐答案
下面是一个什么样迈克尔在谈论一个例子。 http://www.phpletter.com/Our-Projects/AjaxFileUpload/
Here is a example of what Michael is talking about. http://www.phpletter.com/Our-Projects/AjaxFileUpload/
这篇关于PHP jQuery的阿贾克斯()文件上传服务器端的理解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!