Consider logically what you're doing here. While the server-side code can indeed see the file, the client-side browser of course can not. And the code currently relies on that by sending this to the client:
<source type="video/mp4" src="E:/Movies/Movie.mp4">
Instead of thinking about the file itself, think about the request that the browser needs to make for the file. The browser is actually making two requests here:
- One for the HTML that PHP outputs
- One for the file in the
src
attribute
For that second request, you need to make another PHP "page". (Though that "page" isn't going to return a web page, it's going to return the actual file.) That second page will need to know which file is being requested and will need two things:
- It needs to know which file the client wants
- It needs to stream the file to the client
For the first part, you can add the file name itself to the query string on the URL. You'll want to be careful here because clients can request any file, so in your server-side code you'll want to ensure that requests for unauthorized files are denied. But essentially the code might look something like this:
$src = "streamMovie.php?file=" . urlencode("E:/Movies/Movie.mp4");
This should result in something like:
<source type="video/mp4" src="streamMovie.php?file=E%3A%2FMovies%2FMovie.mp4">
Now steamMovie.php
knows which file is being requested by checking the value in $_GET["file"]
. Then it just needs to stream that file. I could go into the details on that part, but it's already been answered elsewhere.