Failed to get reverse video after extract contents, and base64 using PHP

I tried to return my video (mp4) after receiving the content, after which I encoded it base64, but my video still does not play. I tried the code below with images and it works. Why doesn't it work with video?

<?php $con=file_get_contents("kecak.mp4"); //kecak.mp4 work to play with <video> </video> tag $en=base64_encode($con); $binary_data='data:'.$mime.';base64,'. $en ; ?> <video width="320" height="240" controls="controls"> <source src="<?php echo $binary_data ?>" type="video/mp4" /> Your browser does not support the video tag. </video> 
+4
source share
2 answers

I believe there is a length limit for base64_encode. When the input is too long, it does not output anything. I do not have your video or its details to test it, but I think that chunk_split can help you here: http://nl.php.net/manual/en/function.chunk-split.php .

+1
source
  // works for me $img_str = base64_encode(file_get_contents($filename)); // encode file header("Access-Control-Allow-Origin: *"); // allow all CORS // dev only header("Content-Type: text/plain"); // resp file header echo($img_str); // echo base64 string 
0
source

Source: https://habr.com/ru/post/1388321/


All Articles