-1

I have a problem with displaying some videos via a php script using readfile(). Some videos give a HTML status 500, others work fine. Something I do wrong, but I have no idea what. Can somebody hint me in the right direction? What might be the reason for error 500 ?

This is a simplified example I tested on my localhost to reproduce the error.

calling script:

<?php
  $videofiles=array("1.mp4", "2.mp4", "3.mp4", "4.mp4");
  for ($i=0; $i < count($videofiles); $i++) {
?>
    <div class="videos">
    <video controls>
        <source src="video.php?v=<?php echo $videofiles[$i]; ?>" type="video/mp4">
    </video>
    </div>
<?php
  }
?>

delivering script video.php:

<?php
  $video=$_GET['v'];  
  header("Content-Type: video/mp4"); 
  header("Content-Length: ".filesize($video));
  readfile($video);
?>

All rights are set correct (if I replace "video.php?v=..." by the direct filepath all videos show). I suspect that it has to do with file size - the larger (> 150MB) are those who do not show, but I don't know... for testing I used videos from the same mobile phone and of the same day without altering them.

  • 2
    check your logs and enable error reporting – Funk Forty Niner Sep 07 '18 at 11:40
  • Any change if you run ob_end_flush(); before readfile? – Mihai Sep 07 '18 at 11:45
  • Paste this piece of code on top of the file & execute. ```error_reporting(E_ALL); ini_set('display_errors', '1');``` It'll show you exact error message whatever you are getting. – Suresh Sep 07 '18 at 11:48
  • https://stackoverflow.com/questions/1053424/how-do-i-get-php-errors-to-display?rq=1 – Nanne Sep 07 '18 at 11:59
  • Although this does not answer your question, I have serious doubts about your video.php - why don't you serve those files directly without PHP? Your serving script really isn't of any use here. – maio290 Sep 07 '18 at 15:34
  • @maio290 Of course in the given example it doesn't make sense to use readfile() . I made this simplified example to not cluster the question with my personal use and to reduce it to the real problem: why it produces error 500. I think it would only inflate the question if I added, for example, the testing of the $_GET input, the file locations and the where and why etc. All that - in this case - would not have helped to illustrate the problem that I had. – Daniel Bauer Sep 08 '18 at 10:30

1 Answers1

0

Thanks for the answers!

I found in the error log:

PHP
Fatal error:  Allowed memory size of 134217728 bytes exhausted (tried to
allocate 138174464 bytes)

After that I inserted in the script

ini_set('memory_limit', '400M' );

this solved the problem.