使用jquery文件上传器和PHP上传多个文件
我正在用php mysql开发一个web应用程序。在这里,要求是,用户应该能够一次上载多个文件,以将它们存储在服务器上。目前我可以使用此功能上载单个文件使用jquery文件上传器和PHP上传多个文件,php,jquery,ajax,file-upload,Php,Jquery,Ajax,File Upload,我正在用php mysql开发一个web应用程序。在这里,要求是,用户应该能够一次上载多个文件,以将它们存储在服务器上。目前我可以使用此功能上载单个文件 $(function(){ var btnUpload=$("#uploadPdf"); new AjaxUpload(btnUpload, { action:"uploadPdf.php", name: "uploadCertPdf", onSubmit: function(file, ext){
$(function(){
var btnUpload=$("#uploadPdf");
new AjaxUpload(btnUpload, {
action:"uploadPdf.php",
name: "uploadCertPdf",
onSubmit: function(file, ext){
if (!(ext && /^(pdf)$/.test(ext))){
alert("Upload File (Supports PDF formats only)");
return false;
}
var stats = $("#resultsOuter");
stats.html('<img src="images/layout/preloader-2.png" />');
},
onComplete: function(file, response){
alert(response);
alert("File uploaded successfully");
window.location="somePage.php";
}
})
});
/**somePage.php file**/
if (isset($_FILES["uploadCertPdf"]))
{
if ($_FILES["uploadCertPdf"]["error"] > 0)
{
echo "Error: " . $_FILES["uploadCertPdf"]["error"] . "<br />";
}
else
{
if(!is_dir($_SERVER['DOCUMENT_ROOT']."admin/pdf/"))
{ echo "not found";
mkdir($_SERVER['DOCUMENT_ROOT']."admin/pdf/", 0777,true);
}
if(file_exists($file))
{ echo "duplicate";
$flag = TRUE;
}
else
{
$uploaddir = '/admin/pdf/';
$uploadfile = $uploaddir . basename($_FILES['uploadCertPdf']['name']);
$path_info = pathinfo($_FILES['uploadCertPdf']['name']);
$type= $path_info['extension'];
if($type == 'pdf')
{
$flag = move_uploaded_file($_FILES['uploadCertPdf']['tmp_name'],$uploadfile);
}else{
echo "You can upload only PDF files";
}
}
}
}
我尝试将数组添加到name属性,但没有成功。您可以使用在上提供的Jquery插件一次上载多个文件。我刚刚在Grails项目上完成了一个多文件上载功能,使用本文作为指导(基于PHP)。如果你想推出自己的-这是一个伟大的参考
检查此链接,它可能会帮助您使用plupload。它有很多选择。感谢您的回复,但我不是在寻找bcoz插件。我已经在使用一个插件,没有足够的时间切换到另一个插件,因为我已经在不同的地方使用了它。因此,我希望有人确定修改我的插件到多个上传场景所需的更改。是的,我尝试过类似的操作,但问题是我没有使用传统的上传按钮,我使用jqueryajax上传文件,它使用iframe动态处理上传。现在,当“上载”对话框打开时,它不允许我选择多个文件。即使我已将“名称”属性添加为数组(类似于您建议的链接中的操作)。感谢本文中的示例实际上使用纯ajax(jQuery)进行了多个文件上传—在IE9及以下版本中,它只默认为传统的单次上传。否则,示例中的代码允许用户选择多个文件,在“更改”事件中,它将上载所有选定的文件。将通过并尝试!谢谢
/**
* Creates invisible file input above the button
**/
_createInput : function(){
var self = this;
var input = d.createElement("input");
input.setAttribute('type', 'file');
input.setAttribute('name', this._settings.name);
input.setAttribute('id', 'file'+this._settings.name);
var styles = {
'position' : 'absolute'
,'margin': '-5px 0 0 -175px'
,'padding': 0
,'width': '220px'
,'height': '30px'
,'fontSize': '14px'
,'opacity': 0
,'cursor': 'pointer'
,'display' : 'none'
,'zIndex' : 2147483583 //Max zIndex supported by Opera 9.0-9.2x 2147483583
// Strange, I expected 2147483647
};