Home > OS >  SEND BLOB VIDEO (FROM WEBRTC) TO A MYSQL SERVER IN PHP
SEND BLOB VIDEO (FROM WEBRTC) TO A MYSQL SERVER IN PHP

Time:06-13

I have tried using some code to get blob uploaded to server, but this code has not functioned as intended. need help in finding where the error is and perhaps how to upload blob video to MySQL server.

The js code I used is

var blob = URL.createObjectURL(recorder.getBlob());
var fd = new FormData();
fd.append('fname', 'test.mp4');
fd.append('data', blob);
$.ajax({
    type: 'POST',
    url: '../../application/controllers/upload.php',
    data: fd,
    processData: false,
    contentType: false
}).done(function(data) {
    alert(data);
});

Then this is the PHP code I tried

foreach(array('video', 'audio') as $type) {
    if (isset($_FILES["${type}-blob"])) {

        echo 'uploads/';
        $fileName = $_POST["${type}-filename"];
        $uploadDirectory = 'uploads/'.$fileName;

        if (!move_uploaded_file($_FILES["${type}-blob"]["tmp_name"], $uploadDirectory)) {
            echo(" problem moving uploaded file");
        }
        echo($fileName);
    }
}

Once I am able to get this working I can be able to insert the data into MySQL database Thank you for helping

CodePudding user response:

you placed your blob into your formdata OBJECT and called it data

fd.append('data', blob);

So when that gets to PHP is will be placed in

$_FILES['data']

Just like as if you had done

<input type="file" name="data">
  • Related