case : i am trying to upload webrecord audio to wordress post . so i have form with post id and input type file “audio_upload”
below is my code snippet
$audio_meta_value = media_handle_upload( 'audio_upload', $pid);
above code works fine.
Issue:
i have added webrecord to my form at bottom , i am able to save audio via below code using ajax , but i am stuck with adding that audio to my post that .
Any possible solution ?
1: Is there any wordpress function that accepts blob data / base64 encode instead of $_FILES to save attachment.
2: can i do append blob data to file input in form so my previous flow will works
code to save audio via ajax
Fr.voice.export(function(blob){
var data = new FormData();
data.append('file', blob);
$.ajax({
url: "server.php",
type: 'POST',
data: data,
contentType: false,
processData: false,
success: function(data) {
// Sent to Server
}
});
}, "blob");
Upload.php
if(isset($_FILES['file'])){
// $audio = file_get_contents($_FILES['file']['tmp_name']);
$audio = $_FILES['file']['tmp_name'];
$newpath = "soundrec/uploaded_audio".time().".wav";
rename($audio,$newpath);
echo $newpath;
}
1
you can do that with the function wp_handle_sideload
https://developer.wordpress.org/reference/functions/wp_handle_sideload/
Steps to make this :
- create a temporary file with the content you need
- pass this filename to function
wp_handle_sideload