Reputation: 457
Hi This is my JS file for plupload
var uploader = new plupload.Uploader({
runtimes : 'html5,flash,silverlight,html4',
browse_button : 'pickfiles', // you can pass in id...
container: document.getElementById('container'), // ... or DOM Element itself
url : '../../assets/php/upload.php',
flash_swf_url : '../js/Moxie.swf',
silverlight_xap_url : '../js/Moxie.xap',
filters : {
max_file_size : '10mb',
mime_types: [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Video files", extensions : "mp4"}
]
},
init: {
PostInit: function() {
document.getElementById('filelist').innerHTML = '';
document.getElementById('uploadfiles').onclick = function() {
uploader.start();
return false;
};
},
FilesAdded: function(up, files) {
plupload.each(files, function(file) {
document.getElementById('filelist').innerHTML += '<div id="' + file.id + '">' + file.name + ' (' + plupload.formatSize(file.size) + ') <b></b></div>';
});
},
UploadProgress: function(up, file) {
document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
},
Error: function(up, err) {
document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
}
}
});
uploader.init();
In my upload.php I return an
echo $name
I would like my plupload to display the $name on upload complete.
I have tried this solution How do I return data via Ajax using Plupload on Upload Complete?
uploader.bind('FileUploaded', function(upldr, file, object) {
var myData;
try {
myData = eval(object.response);
} catch(err) {
myData = eval('(' + object.response + ')');
}
alert(myData.result);
But when I add it to my code it keeps returning "Your browse does not support HTML5,Flash,silverlight,html4"
If I take out the Fileuploaded method it works fine.
Upvotes: 1
Views: 688
Reputation: 457
Worked it out. Should go like this.
UploadProgress: function(up, file) {
document.getElementById(file.id).getElementsByTagName('b')[0].innerHTML = '<span>' + file.percent + "%</span>";
},
FileUploaded: function(up, file, info) {
// Called when a file has finished uploading
document.getElementById('console').innerHTML += "#" + info.response + ": ";
var myData;
try {
myData = eval(info.response);
} catch(err) {
myData = eval('(' + info.response + ')');
}
$("#video_id").val(info.result);
},
Error: function(up, err) {
document.getElementById('console').innerHTML += "\nError #" + err.code + ": " + err.message;
}
Upvotes: 2