Jump to content

Load file through PHP


rondog

Recommended Posts

I have some FLV files above web root. I want to feed my flv player a php file and an ID. I need that php file to return an flv file basically. So if someone has firebug or something they wont see a video path, but instead see something like:

 

fileserve.php?id=4679

 

I dont care if a logged in user go directly to that link and it prompts them with a download or whatever. I just want to avoid having a non logged in user do that.

Link to comment
Share on other sites

Ok that is working..I am seeing the video load in firebug. This is my code right now:

<?php
include("connect.php");
if ($_SESSION['loggedIn'] == true)
{
$id 	= $_GET['id'];

$query 	= mysql_query("SELECT filename FROM video WHERE id = '$id'");
$row 	= mysql_fetch_array($query);

header("Content-type: video/flv");
echo readfile("../../../armsmedia/videos/".$row['filename']);
}
else
{
echo "invalid action";
}
?>

 

My video player is throwing this error:

VideoError: 1005: Invalid xml: URL: "inc/fileserve.php?id=4679" No root node found; if url is for an flv it must have .flv extension and take no parameters
at fl.video::SMILManager/http://www.adobe.com/2007/flash/flvplayback/internal::xmlLoadEventHandler()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at flash.net::URLLoader/onComplete()

 

I know this isnt a flash forum, but who knows, someone may know what is going on here. I think I am outputting the raw data in the php file and flash is seeing that and not a video file

Link to comment
Share on other sites

ok figured it out!

 

fileserve.php:

<?php
include("connect.php");
if ($_SESSION['loggedIn'] == true)
{
$id 	= $_GET['id'];

$query 	= mysql_query("SELECT filename FROM video WHERE id = '$id'");
$row 	= mysql_fetch_array($query);

$filename = "../../../armsmedia/videos/".$row['filename'];
header( 'Content-Description: File Transfer' );
    header( 'Content-Type: application/octet-stream' );
    header( 'Content-Disposition: attachment; filename='.basename( $filename ) );
    header( 'Content-Transfer-Encoding: binary' );
    header( 'Expires: 0' );
    header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' );
    header( 'Pragma: public' );
    header( 'Content-Length: ' . filesize( $filename ) );
    ob_clean();
    flush();
    readfile( $filename );
    exit;

}
else
{
echo "invalid action";
}
?>

 

The problem with the flash was, the path it needs has to be an flv extension and has to have no parameters which it obviously did.

 

I made a rewrite rule thanks to http://dennisjaamann.com/blog/?tag=movie

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^videos/([^/]+).flv inc/fileserve.php?id=$1 [NC]

 

So now rather than passing this path to my flv player:

http://mysite.com/fileserve.php?id=4679, I pass:

http://mysite.com/videos/4679.flv and it works!

 

That link is also only accessible if you're logged in which is exactly what I was looking for!

 

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.