Skip to content
Advertisement

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

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

Advertisement

Answer

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">
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement