Jquery BlueImp how to change filename before upload?
require('UploadHandler.php');
class CustomUploadHandler extends UploadHandler {
protected function trim_file_name($file_path, $name, $size, $type, $error, $index, $content_range) {
$name = 'First_' . microtime(true);
$name = str_replace('.', '', $name);
return $name;
}
}
$upload_handler = new CustomUploadHandler();
In your custom file index.php initialize this function of UploadHandler.php
This can be achieved with only change the trim_file_name() function to the following in the UploadHandler.php file.
protected function trim_file_name(VARIABLES) {
$name = uniqid();
return $name;
}
and that's all
Here's a client-side solution specific to BlueImp. It uses BlueImp's "add" callback. My example will strip commas from the filename.
$('#fileupload').fileupload({
add: function (e, data) {
$.each(data.files, function (index, file) {
//set new name here
var newname = data.files[index].name.replace(",", "");
Object.defineProperty(data.files[index], 'name', {
value: newname
});
});
$.blueimp.fileupload.prototype.options.add.call(this, e, data);
}
})