Stream video located outside the root - php

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, which triggers a php script to access the file and play it.
Is this possible?
I can seem to find any info on any forums or Google.
Can I stream it direct to the browser?
I had this working when the files were inside the root.
I am holding the url of the file in a var:
$file_url = "../users/$u_id/$folder_name/$file_name";
And trying to stream the video using html5 player video.js using this:
<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_url" type='$file_type' />
</video>
</div>
Many thanks
Alan

Related

Embedded video player not showing and not playing a video file

I am developing a PHP backend to my mobile app.
There is a part where I need to show and play a hosted video file.
This is how am I trying it:
$data[$i]['video'] = '<video controls width="500", height="300><source src="pacientes/'.$data[$i]['video'].'" type= "video/mp4; codecs="avc1.42E01E, mp4a.40.2"></video>';
Here hou have the value for $data[$i]['video'] that should be an example of the kind of video files I will find in he backend
32365bec-7ec8-4b16-a91c-58e12f68cdba1575964120438935622.mp4
And here yoy have the video file URL
https://capenergy-app.com/administrar/application/admin/pacientes/32365bec-7ec8-4b16-a91c-58e12f68cdba1575964120438935622.mp4
And here you a screenshot from the video player using the above code to show it.
The video is not played when clicking on the play button, and the video duration is set to 0:00.
What do I need to change to my code to show the video and let me play it?
You must put the full video path at the source's src
<source src="full_path" > </source>
Double check spelling, for example: some " are missing. And there is no need to add a , after attributes.
Fix:
$data[$i]['video'] = '<video controls width="500" height="300"><source src="pacientes/'.$data[$i]['video'].'" type= "video/mp4"; codecs="avc1.42E01E, mp4a.40.2"></video>';

PHP read MP4 file with another extension

I work in a museum, our website has many .MP4 videos. I changed their extensions to .MUS to make them more difficult to download (most people don't know how to right click the webpage, click the <video> tag to download it and then rename it). Videos show fine. It looks like this :
<video width='640px' height='480px' controls='controls' />
<source type='video/mp4' src='dinos.mus'> ◄█■■■
</video>
Now I moved the videos to a protected directory outside WWW, then I use PHP to read them, like this :
<video width='640px' height='480px' controls='controls' />
<source type='video/mp4' src='open_file.php?file=dinos.mp4'> ◄█■■■
</video>
And this is open_file.php :
header( "Content-Type: video/mp4" );
readfile( "/home/" . $_GET["file"] );
It works fine... until I change the extensions from .MP4 to .MUS, then the videos are no longer shown :
<video width='640px' height='480px' controls='controls' />
<source type='video/mp4' src='open_file.php?file=dinos.mus'> ◄█■■■
</video>
I don't understand why : it's the same file, I send the proper header with PHP, the <video> tag has the proper type. Actually, without PHP the <video> tag works fine with the .MUS files, so the problem seems to be PHP.
My question is : how can I read the .MUS files and send them to be interpreted as MP4?
I have tested your code, the Content-Type: video/mp4 and readfile should work (it should not be related to the file extensions, imagine if you get the file data from a BLOB, it should also work)
But just if the home directory is relative ,then please use "./home/" instead of "/home/"
and
make sure that the directory / file permissions are set properly. Say make sure the home directory is EXECUTABLE (chmod a+x for home directory) and the mus files are READ-PERMITTED (chmod a+r for the MUS files)
So this open_file.php works:
<?php
header("Content-Type: video/mp4");
readfile("./home/" . $_GET["file"]);
?>
See a working example here:
http://www.createchhk.com/SO/testSO20Nov2021b.php
code as follows:
<video width='640px' height='480px' controls='controls' />
<source type='video/mp4' src='open_file.php?file=test2.mus'>
</video>
This wouldn't really protect the file. You could protect the file by hosting it on another server, buffering the video, and then renaming the file for the next user, effectively deleting the file until it gets reloaded. This would take a while to code though.
A different way to do this though, would be to use blob urls. These are what YouTube uses and it stops people from easily finding the video URL.
You can use the PHP code below to do this:
<?php // php at top of page
$video = file_get_contents('./location/to/file/from/page.mp4');
$video_code = base64_encode($video);
?>
Then, where you have the video file, you can do this:
<video width='640px' height='480px' controls='controls' controlslist='nodownload' />
<source type='video/mp4' src='<?php echo $video_code; ?>'>
</video>
If anyone tries to grab the video URL and open it, it will tell them that the file has been moved. They also cannot download the file. I would also recommend adding oncontextmenu='return false;' to the video for a bit more security.
I think the MIME type for .MUS files is application/octet-streamheader( "Content-Type: application/octet-stream" );

How to show pdf file coming from cloud server

I have pdf link file coming from cloud server and i put it into iframe to show it but when i open the page, it direct to download this pdf file and didn't show the file itself, also i used embed and object and it doesn't appear anything.
<iframe src='{$finalurl}' width='1000' height='1000' align='center'></iframe>
Are you required to use an i-frame?
And do you just want to show it, or download it to your 'own' server and show it? That's a big difference.
If you just want to show it (and keep it where it is):
<embed src="http://cloudservice/yourpdf.pdf" width="1000" height="1000" type='application/pdf'>
Good luck

Masking/redirecting a video URL via PHP

I'm desperately (hours of research and no luck so far) trying to create a PHP page which can be used as a path for video embedding. I'm doing this so that I can give out a path to 3rd parties, that they can use for embedding, which won't change, even if I have to host the video elsewhere.
I've tried using the code referenced here...
Reading mp4 files with PHP
... but it doesn't work at all for me.
The video files will be hosted on a CDN and 3rd parties will need fixed links that they can embed on their own sites like:
<div data-swf="$resourcePath/resources/flowplayer.commercial-5.4.3/flowplayer.swf" class="flowplayer is-splash play-button" data-ratio="0.5625">
<video>
<source type="video/mp4" src="http://www.mycdndomain.com/embed/loader.php?v=1"/>
</video>
</div>
Thanks in advance.
-Josh

Finding embed site for a flash app

Heyas. I have an flash app that I'm working on that can be embedded on other websites (like YouTube videos), but we want to know what website the user is viewing the site on. Is there any way to tell what site the app is embedded on that the user is viewing on?
The original app is written in flash/actionscript and php running on the server, if that helps. Thanks.
You can simply retrieve the HTTP referrer header via php, store it somewhere and than serve your flash content...
<?php
// served from http://yoursite.net/your_flash.php
//read the referer header
$referer_url = (isset($_SERVER['HTTP_REFERER']))? $_SERVER['HTTP_REFERER'] : "";
//store it somewhere...
//read the swf file
$swf=file_get_contents('flash_app.swf');
//spit the flash content out with the proper header
header('Content-type: application/x-shockwave-flash');
echo $swf;
?>
Embed code, to be pasted by third party websites in their HTML:
<object width="550" height="400">
<embed src="http://yoursite.net/your_flash.php" width="550" height="400">
</embed>
</object>

Categories