Why doesn't specifying the full path of an mp4 in video file work when relative path does using PHP on apache/Ubuntu 20.04

549 views Asked by At

I've got a number of mp4 video files in a folder. When I use scandir with a relative path, the files display correctly in the webpage and can be played.

Browser html looks like this.

<div class="box">
<video src="./mp4Files/video1.mp4" type="video/mp4" loop class="clip" controls
</video>
</div>

When I specify the full path of the file, scandir finds the files, the browser constructs the videos in a but the error appears - no video with supported format and MIME type found.

Browser html looks like

<div class="box">
    <video src="/var/www/html/VideoRecTest/mp4Files/video1.mp4" type="video/mp4" loop    
    class="clip" controls></video>
 </div>

btw, open_base_dir has no value when I do a phpinfo().

1

There are 1 answers

2
Jaquarh On

These are not webservers

  • html
  • php
  • javascript

These are webservers

  • nginx
  • apache2

Your webserver's vhost configuration will contain a path that is served as the root directory.

/var/www/html/ becomes 0.0.0.0/ or example.com/.

When you then want to visit, for example index.php the URI would be 0.0.0.0/index.php which uses /var/www/html/index.php.

Your use-case here is configured at /var/www/html and thus giving a path of /var/www/html/VideoRecTest/mp4Files/video1.mp4 would merely give an absolute path of

/var/www/html/var/www/html/VideoRecTest/mp4Files/video1.mp4

Your video would, however, be accessible perfectly fine just at

/VideoRecTest/mp4Files/video1.mp4

Since your webserver is already configured to serve directories and files from the root directory /var/www/html.

You also cannot traverse below the specified root directory. 0.0.0.0/../ will translate to /var/www/html/ and thus redirect back to 0.0.0.0/.

Note, the root directory can be changed in your vhost configuration. I use /var/www/html as an example due to it being the default.