选择一个文件上传后,我希望文件上传到数据库没有点击一个按钮。这是如何使用jQuery完成的?
使用jQuery选择文件后开始上传。
我想选择这样的文件: http://i.stack.imgur.com/0408T.gif
<input type="file" valign="baseline" />
选择一个文件上传后,我希望文件上传到数据库没有点击一个按钮。这是如何使用jQuery完成的?
使用jQuery选择文件后开始上传。
我想选择这样的文件: http://i.stack.imgur.com/0408T.gif
<input type="file" valign="baseline" />
假设您使用表格:
// select the file input (using a id would be faster)
$('input[type=file]').change(function() {
// select the form and submit
$('form').submit();
});
编辑:为了保持这个答案了最新:
有通过AJAX上传文件,而这里介绍黑客的好办法: http://net.tutsplus.com/tutorials/javascript-ajax/uploading-files-with-ajax/
使用jQuery的插件uploadify
这是伟大的插件,它有许多选项,并自动上传,太
$(document).ready(function() {
$('#file_upload').uploadify({
'uploader' : '/uploadify/uploadify.swf',
'script' : '/uploadify/uploadify.php',
'cancelImg' : '/uploadify/cancel.png',
'folder' : '/uploads',
'auto' : true
});
});
我不使用插件 –
如果您想要使用html上传器,则非商业项目花费5美元,商业项目花费100美元。 – Adam
刚才设置的自动为true ..'auto':true
你可以添加一个链接,你看到这个工作,因为我找不到像这样的东西。 –
发送数据到数据库必须使用ajax调用吗?请解释更多... –
@Mehd:这不是ajax。当您更改文件时,表单将自动开始发送 – genesis
@Mehd:查看完整上传解决方案的成因答案。 – binarious