I currently have a file called index.php
in my web root folder /var/www/html/
which should load an image and a video in a directory outside of the web root.
The image and a video file is located outside the web root folder as follows: /var/www/media/image.jpg
and /var/www/media/movie.mp4
.
To access the image file, I have created a php file within the web root folder called serve_image.php
with the following contents:
<?php
header('Content-Type: image/jpg');
readfile("../media/image.jpg");
?>
then, within index.php, i load this image into an <img>
element as follows:
<html>
<body>
<img width="320" height="240" src="serve_image.php"/>
</body>
</html>
and the image is correctly displayed.
If I try to do the same thing with the mp4 file, it does not show the video. I have created a php file within the web root folder serve_movie.php
with the following contents:
<?php
header('Content-Type: video/mp4');
readfile("../media/movie.mp4");
?>
then, within index.php, i load try to load this movie into an <source>
element within a <video>
element as follows:
<html>
<body>
<video width="320" height="240" controls autoplay>
<source src="serve_movie.php" type="video/mp4"/>
</video>
</body>
</html>
However, no video is shown.
What do I need to do to correctly load the video?
Your code looks correct, and when I've just tested a very similar script, it has worked perfectly.
A couple of thoughts:
To enable error reporting, add the following to your video script (serve_movie.php) before any other code:
error_reporting(E_ALL);
ini_set('display_errors', true);
ini_set('html_errors', true);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.