RecordRTC/RecordRTC-to-PHP/README.md
Please check tutorial: RecordRTC and Upload to PHP Server
This demo allows you record and upload to PHP server. Files on PHP server are auto-deleted as soon as you leave this page.
This demo runs top over RecordRTC: https://github.com/muaz-khan/RecordRTC
This demo works in Chrome, Firefox, Opera and Microsoft Edge. It even works on Android devices.
Following snippets explains how to POST recorded audio/video files to PHP server. It captures Blob and POST them using XHR2/FormData.
<?php
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);
}
}
?>
var fileType = 'video'; // or "audio"
var fileName = 'ABCDEF.webm'; // or "wav"
var formData = new FormData();
formData.append(fileType + '-filename', fileName);
formData.append(fileType + '-blob', blob);
xhr('save.php', formData, function (fName) {
window.open(location.href + fName);
});
function xhr(url, data, callback) {
var request = new XMLHttpRequest();
request.onreadystatechange = function () {
if (request.readyState == 4 && request.status == 200) {
callback(location.href + request.responseText);
}
};
request.open('POST', url);
request.send(data);
}
RecordRTC.js is released under MIT licence . Copyright (c) Muaz Khan.