Here is my javascript code.
function multyTypeUploadAttachments(file,classId,splAttrId){
var campaignID = $('#wk_custCampID').val();
if(campaignID == ""){
var campaignID = $('#wk_edit_camp_ID').val();
}
var fileName = $('#'+file.id).val().replace(/C:\\fakepath\\/i, '');//form_skuAttachment
var lastChar = file.id[file.id.length -1];
var upload_data = new FormData($('#wk_multy_form_AttrOptionAttachment'+classId+"-"+splAttrId+"-"+lastChar)[0]);
$.ajax({
url: BASEPATH + 'c_workOrder/uploadSKUAttachments/'+file.id+'/'+campaignID,
type: 'POST',
data: upload_data,
mimeType: "multipart/form-data",
contentType: false,
cache: false,
processData: false,
success: function (res) {
$('#'+file.id+'-hidden').val(res);
$('#'+file.id+'-OrgNamehidden').val(fileName);
toastr.success('Upload success');
return;
},
error: function (res) {
toastr.error(res);
}
});
}
and here is php code
function uploadSKUAttachments($file,$campaignID){
$ext = substr(strrchr(basename($_FILES[$file]["name"]), '.'), 0);
$fileName = basename($_FILES["$file"]["name"]);
$name = basename($fileName,$ext);
$createdTime = time();
$target_dir = "./uploads/attachments/";
$target_file = $target_dir .$campaignID."_".$name."_".$createdTime.$ext;
$errorFlag = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
$fullFineName= $name."_".$createdTime.$ext;
if ($errorFlag == 1) {
if(file_exists($target_file)){
echo true;
}else if (move_uploaded_file($_FILES["$file"]["tmp_name"], $target_file)) {
echo $fullFineName;
} else {
echo "Sorry, there was an error uploading your file";
}
}
}
And the error I get is as follows:
Severity: Notice
Message: Undefined index: wk_multy_AttachmentDiv-6-10
Filename: controllers/C_workOrder.php
Line Number: 83
Sorry, there was an error uploading your file