Native html5 player help with Upload

  You are currently not logged in. You can view the forums, but cannot post messages. Log In | Register

04-Nov-17 10:34
Native html5 video player starts, stops & records successfully, but need help with Upload.
This web video player starts, stops, records and plays back successfully, but the Upload portion needs help. Although the console shows "Success", no file actually arrives. Any guidance/suggestion/remedy to get the recorded video to Upload to a folder, will be welcomed. Thanks.



..............
<button class="start" disabled>Start</button>
<button class="stop" disabled>Stop</button>
<button class="reset" disabled>Reset</button>
<button class="upload" onclick="InitUploading()" disabled>Upload</button>

<script>

const video = document.querySelector('video')
const start = document.querySelector('.start')
const stop = document.querySelector('.stop')

const initRecorder = stream => {

const recorder = new MediaRecorder(stream)

video.srcObject = stream
start.removeAttribute('disabled')

video.addEventListener('loadedmetadata', () => {
video.play()
})

recorder.addEventListener('dataavailable', ({ data }) => {
video.srcObject = null
video.src = URL.createObjectURL(data)
})

start.addEventListener('click', () => {
stop.removeAttribute('disabled')
recorder.start()
})

stop.addEventListener('click', () => {
recorder.stop()
})


// Upload the video blob as form data


upload.addEventListener('click', () => {
const body = new FormData()

body.append('myvideo', blob)

fetch('upload.php', { method: 'POST', body })
.then(() => console.log('Success!'))
.catch(console.error)

})

}

navigator
.mediaDevices
.getUserMedia({ video: true })
.then(initRecorder)
.catch(console.error)

</script>
Here's the upload.php file:


Here's the upload.php file:



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

//echo 'uploadWC/';

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

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

echo($fileName);
}
}
?>
05-Nov-17 18:59

$uploadDirectory = 'uploadWC/'.$fileName;


After that operation $uploadDirectory is no longer a directory, so saving files to that path WILL fail.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/

 
New posts
Old posts

Follow Elated