Home » Javascript » php simple livestream not working

php simple livestream not working

Posted by: admin November 1, 2017 Leave a comment

Questions:

I want to make a very simple version of Twitch (client side and server side, no accounts, only two users) in the fileupload.php the first user should choose a video and in the streamer.php the second user watch the video before the video is 100% uploaded.

In my program it work only if the video is 100% uploaded, but I want if 1% is uploaded, the other person can watch the 1% of the video.

Preferable with PHP and without a library.
Sorry for my bad English I am just learning.

Thanks alot for your answers!

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>
Answers: