I have a PHP/JS fileupload and I want to stream a video before it is 100% uploaded.
How I make that?
fileupload.html (JS, uploadFile()):
var file = document.getElementById("file1").files[0];
var formdata = new FormData();
formdata.append("file1", file);
var ajax = new XMLHttpRequest();
ajax.upload.addEventListener("progress", progressHandler, false);
ajax.open("POST", "file_upload_parser.php");
ajax.send(formdata);
fileupload.html (html)
<form id="upload_form" enctype="multipart/form-data" method="post">
<input class="fileUpload" type="file" name="file1" id="file1"><br>
<input id="uploadBtn" type="button" value="Upload File" onclick="uploadFile()">
</form>
file_upload_parser.php:
<?php
$fileName = $_FILES["file1"]["name"];
$fileTmpLoc = $_FILES["file1"]["tmp_name"];
if(move_uploaded_file($fileTmpLoc, "uploads/$fileName")){
echo "complete";
}
?>
VideoStream.php: https://gist.github.com/ranacseruet/9826293
streamer.php
<?php
$path = $_GET['path'];
include "VideoStream.php";
$stream = new VideoStream($path);
$stream->start();exit;
?>
<video controls preload="auto" src="<?php echo $path ?>" width="100%"></video>