Jump to content

Stream video from outside root?


frobak

Recommended Posts

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

Link to comment
Share on other sites

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 by frobak
Link to comment
Share on other sites

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 by frobak
Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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;
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.