我想向我的 dropzone 文件上传器添加一个按钮上传。目前它是在选择文件或将文件拖入放置区域后直接上传文件。我要做的是: 1.选择或拖放要上传的文件。2. 验证 3. 点击或按下按钮上传上传文件。
注意:文件只有在按下按钮上传后才被上传。
这是我的表格
<form id='frmTarget' name='dropzone' action='upload_files.php' class='dropzone'>
<div class='fallback'>
<input name='file' type='file' multiple />
</div>
<input id='refCampaignID' name='refCampaignID' type='hidden' value=\ "$rowCampaign->CampaignID\" />
</form>
这是我的 JS
Dropzone.options.frmTarget =
{
url: 'upload_files.php',
paramName: 'file',
clickable: true,
maxFilesize: 5,
uploadMultiple: true,
maxFiles: 2,
addRemoveLinks: true,
acceptedFiles: '.png,.jpg,.pdf',
dictDefaultMessage: 'Upload your files here',
success: function(file, response)
{
setTimeout(function() {
$('#insert_pic_div').hide();
$('#startEditingDiv').show();
}, 2000);
}
};
这是我的 php 发布请求
foreach ($_FILES["file"] as $key => $arrDetail)
{
foreach ($arrDetail as $index => $detail) {
//print_rr($_FILES["file"][$key][$index]);
$targetDir = "project_images/";
$fileName = $_FILES["file"]['name'][$index];
$targetFile = $targetDir.$fileName;
if(move_uploaded_file($_FILES["file"]['tmp_name'][$index],$targetFile))
{
$db = new ZoriDatabase("tblTarget", $_REQUEST["TargetID"], null, 0);
$db->Fields["refCampaignID"] = $_REQUEST["refCampaignID"];
$db->Fields["strPicture"] = $fileName;
$db->Fields["blnActive"] = 1;
$db->Fields["strLastUser"] = $_SESSION[USER]->USERNAME;
$result = $db->Save();
if($result->Error == 1){
return "Details not saved.";
}else{
return "Details saved.";
}
}else{
return "File not uploaded.";
}
}
}