I created a software that record the voice and create the Blob:
blob = new Blob(chunks, { 'type' : 'audio/mp3; codecs=opus' });
where chunks are
mediaRecorder.ondataavailable = function(e) {
chunks.push(e.data);
}
Then with ajax, I upload the blob with formData to a Codeigniter server:
var formData = new FormData();
formData.append("s_registra", blob);
formData.append('<?= csrf_token() ?>', '<?= csrf_hash() ?>');
$.ajax({
url: '<?php echo site_url('/accetta') ?>',
type: 'POST',
data: formData,
processData: false,
contentType: false,
error: function(xhr,status,error) {
var err = eval("(" + xhr.responseText + ")");
console.log(err.Message);
},
success: function(data) {
console.log(data);
}
});
In the controller (codeigniter 4.3.6) on the server I use this code to save the blob into a mp3 file. But when you try to play the mp3, it doesn't work. Where are the problems?
$current = file_get_contents($this->request->getFile('s_registra'));
$ritorno = file_put_contents(FCPATH . 'uploads/blob/prova.mp3' , $current);