On a recent project I was attempting to get pluploader to set custom file names for uploaded images. After much googling I still had no solution, so I started fiddling with the file properties. Here is my solution:
<script type="text/javascript">
$(function() {
$("#uploader").pluploadQueue({
runtimes : 'html5,flash',
url : '/plupload/upload.php',
chunk_size : '1mb',
rename : true,
resize : {width : 1024, height : 768, quality : 90},
filters : [
{title : "Image files", extensions : "jpg,gif,png"},
{title : "Zip files", extensions : "zip"}
],
flash_swf_url : '/plupload/js/plupload.flash.swf',
});
var uploader = $('#uploader').pluploadQueue();
$('form').submit(function(e) {
if (uploader.files.length > 0) {
uploader.bind('StateChanged', function() {
if (uploader.files.length === (uploader.total.uploaded + uploader.total.failed)) {
$('form')[0].submit();
}
});
uploader.start();
} else {
alert('You must queue at least one file.');
}
return false;
});
uploader.bind('FileUploaded',function(up,file){
console.log(file);
});
//generate a random id
var id = Math.floor(Math.random()*100000);
uploader.bind('FilesAdded',function(up,files){
var i = 1;
$(files).each(function(){
var fileExt = this.name.match(/\....$/);
this.name = adid+'_'+i+fileExt;
i++;
console.log(this);
});
});
});
</script>
The Important bit is the FilesAdded event at the end. what its doing is changing the file.name property to a predetermined id suffixed by a counter. this results in the file being upladed with the value in file.name rather than the file name from the local file system