Upload Multiple Files With Uploadify - Need Id From Input Field
I have multiple input fields on one page. Each input field have a text input and a file upload field. The current workflow looks like the following: Directly after the upload the
Solution 1:
You can setup uploadify using jQuery .each()
. This will allow you to set an id to be passed through the formData like this:
$('.iconupload').each(function() {
var $iconUpload = $(this);
$iconUpload.uploadify({
'swf' : '<?phpecho SUBFOLDER; ?>/swf/uploadify.swf',
'uploader' : '<?phpecho SUBFOLDER; ?>/includes/uploadify.php',
'formData' : {'folder' : '<?phpecho IMG_UPLOAD_ICONS; ?>', 'id' : '<?phpecho$_SESSION['ID']; ?>', 'type' : 'icon', 'uploadId': $iconUpload.attr("id")},
'multi' : false,
'auto' : true,
'removeCompleted': false,
'queueSizeLimit' : 1,
'simUploadLimit' : 1,
'fileTypeExts' : '*.jpg; *.jpeg; *.png; *.gif',
'fileTypeDesc' : 'JPG Image Files (*.jpg); JPEG Image Files (*.jpeg); PNG Image Files (*.png), GIF (*.gif)',
'onUploadError' : function(file, errorCode, errorMsg, errorString) {
alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
},
'onUploadSuccess': function(file, data, response) {
//alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
}
}
});
If you do not want to save the data within uploadify.php, you can save it in onUploadSuccess
like this:
'onUploadSuccess': function(file, data, response) {
saveIconData($(iconUpload.attr("id"), file.name);
}
functionsaveIconData(id, fileName) {
// Save via ajax
}
To save data via ajax, you can use jQuery's $.ajax()
method. You would setup the ajax call something like this:
$.ajax({
url: "urlToPhpFile.php",
data: { iconID: value, iconFileName: value },
success: function(result) {
// do something on success of save
}
});
Post a Comment for "Upload Multiple Files With Uploadify - Need Id From Input Field"