I am using this AJAX File Upload plugin:
http://www.phpletter.com/Demo/AjaxFileUpload-Demo/
I made this function that will loop through all file inputs
function ajaxFileUpload() {
$('input[type=file]').each(function() {
$.ajaxFileUpload ({
url:'upload.inc.php',
secureuri:false,
fileElementId:this.id,
dataType: 'json'
})
});
return false;
The problem is, I am uploading files to two different folders. All file inputs have 'name="image"' on them. So I need to create a conditional statement to tell the program what folder I should put them in. But in order for me to do this, I need to get the class the file input so I can create something like this:
switch(fileInputClass) {
case 'mainImage':
//upload to folder 1
break;
case 'subImage':
//upload to folder 2
}
So how can I pass the class string to my 'upload.inc.php' so that I can conditionally tell what folder it should be uploaded to? Thanks!
You can pass it as a querystring parameter along with the url.
Try something like this
function ajaxFileUpload() {
$('input[type=file]').each(function() {
$.ajaxFileUpload ({
url: getUploadUrl(this.className),
secureuri:false,
fileElementId:this.id,
dataType: 'json'
})
});
return false;
}
function getUploadUrl(class){
switch(class) {
case 'mainImage':
return 'upload.inc.php?uploadfolder=folder1'
case 'subImage':
return 'upload.inc.php?uploadfolder=folder2'
}
}
On the server side get the querystring value using $_GET['uploadfolder']