I am application a website using PHP, MySQL and PHPMyAdmin. I can store and retrieve images from it using ($_FILES) approach. I have a problem though, I want to know how I can store and retrieve audio paths from database and display it. The audios ARE NOT UPLOADED are RECORDED with record.js. I am struggling to accomplish this to save the audio to the file system (folder) path then to the database. what is the best way and how? I would be grateful for any help, Thanks.
I repeat I am NOT ULOAPING THE THE AUDIO USING INPUT ELEMENTS I AM RECORDING IT.
I will show my code snippets below upload file receiving the file from js and
js sending the file once stopped recording
mediaRecorder.onstop = (ev)=> {
let blob = new Blob(veepoData, { 'type' : 'audio/ogg; codecs=opus' });
let audioURL = window.URL.createObjectURL(blob);
/*** Div with url holder ***/
/* dataUrlDiv.innerHTML = audioURL;*/
/** Audio controls, for preview the recording**/
audioSave.src = audioURL;
VeepoRec(blob);
}
mediaRecorder.ondataavailable = function(ev) {
veepoData.push(ev.data);
}
function VeepoRec(blob) {
var fd = new FormData();
fd.append('file', blob);
$.ajax({
url: 'action.php',
data: fd,
type: 'post',
contentType: false,
processData: false,
success: function(response){
if(response != 0){
console.log('upload success');
}
else{
console.log('failed');
}
},
});
};
getting the file from action.php
if(isset($_FILES['file'])) {
$audio = ($_FILES['file']['tmp_name']);
var_dump($_FILES['file']['tmp_name']);
die();
$target_path = 'veepos/' . $audio;
$veepo_rec = '<audio class="veepoRec" controls="controls" src="'.$target_path.'"></audio>';
if(move_uploaded_file($target_path))
{
$veepo_rec = '<audio class="veepoRec" controls="controls" src="'.$target_path.'"></audio>';
}
}
'; – Ab Kabane Oct 19 '20 at 12:05
'; } } – Ab Kabane Oct 19 '20 at 13:43