Stream video outside of root

I'm storing mp4 videos in a folder outside of the root, but need to stream them to a password protected webpage.  I tried this code, but it isn't seeing the files.  (I'm using an Apache webhost)

             <video width="500" height="282" controls>
              <source src="$videoPath<?php echo $video_file;?>" type="video/mp4">
              <source src="movie.ogg" type="video/ogg">
                  Your browser does not support the video tag.

The error "No video with supported format and MIME type found" shows

When I put the video in the root and switch the path, it works fine.

Any help is greatly appreciated.


Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Alias /videos /mnt/usb
You can alias single files too
stkoontzAuthor Commented:
I don't know what you mean by 'alias'.  Can you tell me how that would fit with my code?

Thanks for responding to help me out.  I appreciate it.

Ray PaseurCommented:
You might consider using a fully-qualified URL.  If the video is not in the web root directory tree, a relative URL is probably not going to work.
Active Protection takes the fight to cryptojacking

While there were several headline-grabbing ransomware attacks during in 2017, another big threat started appearing at the same time that didn’t get the same coverage – illicit cryptomining.

stkoontzAuthor Commented:
The URL I'm using is the URL my hosting company has me use to access files outside of the public_html folder.  It's the same URL I use in other applications to access PDF files stored outside the public folder.  Would a fully-qualified URL point to the public_html folder?

Thanks for joining in to help.

You must start with public_html.
In this case you can send files using PHP, but nothing else (If you do not show code noone can help)
With "Apache Webhost" usually a full control of httpd.conf is presumed.
stkoontzAuthor Commented:
My first post has the code I'm using to try to play the videos on the page.  

I'm manually uploading the files myself through FTP, so there's no code to show for the file upload.

It's a very basic system to give access to only a few people to watch the videos.  I just don't want the videos to be accessible unless someone has the login information.  In other words, found if someone does a Google search.

Does that help to clarify the questions?


Then you need to check the authorization and send video file in php
stkoontzAuthor Commented:
Can you help me with how I would do that?
Ray PaseurCommented:
This article can show you how to password-protect a page.

That's only part of the issue, though.  If you want to create an HTML link to a video file, your situation is conceptually the same as the publisher who wants to put his photos online, but prevent anyone from stealing the photos -- it is almost impossible to achieve that because the browser must have a copy of the resource (photo, video, PDF, whatever) in order to display it.

You might consider running the PHP script to create a temporary folder, copy the video into that folder, then generate the HTML for the web page.  You can use a garbage collection algorithm or a cron job to delete anything in the temporary folder that is older than X minutes, where X is the run-time for the video.

You might also create a password-protected PHP script that just copies the video to the stdout stream using something like fpassthru().  I have never done this, but it would not be hard to test.  If you can use the URL of the PHP script in the source tag, you should be OK.  You may have a bit of a research project on the correct http headers for video.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
stkoontzAuthor Commented:
I wrote a script to copy the files into a temporary directory.  Thanks, Ray, for the suggestion.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.