frobak Posted October 28, 2013 Share Posted October 28, 2013 Hi, before i get burried in trying to create the code, I was hoping to get some advice before moving forward. I am creating a video sharing app for a client. The videos are highly confidential, so i want to store them outside the root and stream them when a user enters a link into a browser. Is this possible? I can seem to find any info on any forums or Google. Can I stream it direct to the browser? Many thanks Alan Quote Link to comment https://forums.phpfreaks.com/topic/283377-stream-video-from-outside-root/ Share on other sites More sharing options...
kicken Posted October 28, 2013 Share Posted October 28, 2013 All you need to do is make sure you send the correct Content-type and Content-length using header, then use readfile to output the video contents. Then you just point your video player at the URL for your PHP file and it should all work fine. Quote Link to comment https://forums.phpfreaks.com/topic/283377-stream-video-from-outside-root/#findComment-1455863 Share on other sites More sharing options...
frobak Posted October 28, 2013 Author Share Posted October 28, 2013 (edited) ok thank for your reply. Currently I am using video.js (html5 player) to stream the files. Which worked when the files were within the root, but since ive moved them out, it doesnt work. The file url is held in a var : $file_stream_url = "../users/$u_id/$folder_name/$file_name"; and the code to stream: <div id="video_box"> <video id="example_video_1" class="video-js vjs-default-skin" controls preload="auto" width="500" height="350" poster="images/img_name.png" data-setup='{"example_option":true}'> <source src="$file_stream_url" type='$file_type' /> </video> </div> Is it possible to use this script, or do i need to rewrite? Edited October 28, 2013 by frobak Quote Link to comment https://forums.phpfreaks.com/topic/283377-stream-video-from-outside-root/#findComment-1455866 Share on other sites More sharing options...
frobak Posted October 28, 2013 Author Share Posted October 28, 2013 (edited) I tried using readfile, this is my player: <div id='video_box'> <video id='example_video_1' class='video-js vjs-default-skin' controls preload='auto' width='500' height='350' poster='images/img_name.png' data-setup='{'example_option':true}'> <source src='https://url_to_file/stream.php' type='video/mp4' /> </video> </div> and the content of the file https://url_to_file/stream.php: <?php $path='../users/100002/Testage/marine.mp4'; header('Content-type: video/mp4'); header('Content-Length: '.filesize($path)); // provide file size readfile($path); ?> but it doesnt do anything, the player says "No video with supported format and MIME type found" and when i look at the source it is just printing the url https://url_to_file/stream.php. If i visit the url above, it streams the video, but obviously not in the player Am i missing something simple? Edited October 28, 2013 by frobak Quote Link to comment https://forums.phpfreaks.com/topic/283377-stream-video-from-outside-root/#findComment-1455931 Share on other sites More sharing options...
.josh Posted October 29, 2013 Share Posted October 29, 2013 well at face value your code is fine (I even setup a test page with it).. I think there's a minor problem with your data-setup attribute not escaping the nested single quotes, but that shouldn't stop the video from properly loading. So your problem must be in not pointing to the correct path. So you say that if you go directly to stream.php the video works, so that path must be right. So are you sure the path in your video src attrib is right? Are you sure the file is even there, spelled correct and all that? Actually on that count, are you sure the variables that make up the path in your stream.php have the correct values in them? $file_stream_url = "../users/$u_id/$folder_name/$file_name"; Where are they coming from? Quote Link to comment https://forums.phpfreaks.com/topic/283377-stream-video-from-outside-root/#findComment-1455955 Share on other sites More sharing options...
frobak Posted October 30, 2013 Author Share Posted October 30, 2013 Hi .Josh Yes its very strange. If i visit stream.php the video plays. I am now not using the below, as I was trying to just echo the URL within the player code, but as its outside the root, i cant access it like that: $file_stream_url = "../users/$u_id/$folder_name/$file_name"; For now I have hard coded the path into stream.php just to try and get it working, hard coded path below: $path='/home/[account_name]/users/100002/Testage/marine.mp4'; And i have also tried $path='../users/100002/Testage/marine.mp4'; they both stream the video fine if you visit stream.php, but doesnt work when i try to access it via: echo <<<EOT <div id="video_box"> <video id="example_video_1" class="video-js vjs-default-skin" controls preload="auto" width="500" height="350" poster="images/img_splash.png" data-setup='{"example_option":true}'> <source src='https://url_to_file/stream.php' type='$file_type' /> </video> </div> <div id='video_details'> <div id='video_details_text'> <h2>Download this video</h2> <p>To download this video, click the download button.<br /><br />Depending on the format of the file, you may need to download the player <a href=''>here</a></p> </div> <div id="video_details_dl"> <form method='POST' action='functions.php'> <input type='hidden' id='download_url' name='download_url' value='$file_url'> <input type='hidden' id='download_type' name='download_type' value='$file_type'> <input type='submit' class='file_download_button clickable' name='submit' value='Download'> </form> </div> </div> EOT; Quote Link to comment https://forums.phpfreaks.com/topic/283377-stream-video-from-outside-root/#findComment-1456198 Share on other sites More sharing options...
.josh Posted October 30, 2013 Share Posted October 30, 2013 i honestly don't know what the problem could be then.. did your video tag code work fine before, when it was pointing to the .mp4 directly, in the same directory? Quote Link to comment https://forums.phpfreaks.com/topic/283377-stream-video-from-outside-root/#findComment-1456203 Share on other sites More sharing options...
frobak Posted October 30, 2013 Author Share Posted October 30, 2013 in my stupidity, i neglegted to try it in different browsers. It works in chrome and safari, but i was trying it firefox, and even more stupidly I didnt look at the errors. As its over ssl, im having issues linking to offsite js files that are hosted over http. I'm getting mixed content errors. I'll try hosting all the files and see if that works. Appreciate your help Quote Link to comment https://forums.phpfreaks.com/topic/283377-stream-video-from-outside-root/#findComment-1456207 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.