• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 771
  • Last Modified:

Header data delvering wmv

Hello,

I'm using the code below to deliver a wmv file however it's not working. Windows media player is run correctly but the status just says ready and the video does not play.

I'm not too familiar with php headers so if anyone can help me with where I've gone wrong that would be great.
header('Content-Description: Play Video');
header('Content-Type: video/x-ms-wmv');
header('Content-Disposition: inline; filename='.$file);
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($file));
ob_clean();
flush();
readfile($file);

Open in new window

0
Mr_Splash
Asked:
Mr_Splash
  • 5
  • 5
1 Solution
 
Ray PaseurCommented:
I can only think of a couple of things.  Balanced quotes matter.  And if you say disposition: inline with filename=$file, I am not sure you need to separately read the file.

HTH, ~Ray
header('Content-Description: Play Video');
header('Content-Type: video/x-ms-wmv');
header("Content-Disposition: inline; filename=$file");
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($file)");
// TRY OMITTING THIS STATEMENT
readfile($file);

Open in new window

0
 
Mr_SplashAuthor Commented:
Thanks for the reply Ray.

However I'm still having problems.

It turns out that my original code does work if I remove the session checking in the file, would checking sessions interfere with headers()? Also the code you provided didn't work even without the session checking.

The problem is the session checking needs to be there. I've added all my code below so hopefully you can see the problem.

It's also worth mentioning if I remove the headers() and have an echo in there the session checking works correctly. i.e. echos if logged in, doesn't if not.

So to sum up both parts are working individually but not together.
<?php
 
session_start();
 
require('db-connection.php');
 
if ($_SESSION['logged-id']!=0 && $_SESSION['logged-ip']==md5($_SERVER['REMOTE_ADDR'])) {
  if (isset($_GET['video'])) {
    $video = mysql_real_escape_string($_GET['video']);
    $found = mysql_fetch_assoc(mysql_query("SELECT * FROM encVideos WHERE id='$video' LIMIT 1"));
 
    $file = "sfhs7ffEgf_eg24tgEGdhgdd234-3tEGdgddw/".$buffer['file'];
				
    header('Content-Description: Play Video');
    header('Content-Type:  video/x-ms-wmv');
    header("Content-Disposition: inline; filename=$file");
    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($file)");
    ob_clean();
    flush();
    readfile($file);
 
  }
}
 
?>

Open in new window

0
 
Ray PaseurCommented:
There's got to be more to the code than you posted here - $buffer is undefined and there is no ob_start()!  Please check to make sure you're posting complete code sets - it makes it a lot easier to follow the issues if we can copy and test without having to guess at external values.

Couple of ideas.  Set error_reporting(E_ALL) so we can see what may be hidden in the warnings.

Also, session_start() probably sets a cookie.

Can you post a link to the page that is getting the error?  I'd like to look at the headers.

Thanks, ~Ray
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
Mr_SplashAuthor Commented:
Hi Ray,

Sorry I tried to remove client identifyable content as well as simplify it as much as I could.

My complete code is below, I've added comments to hopefully help explain what's happening.

The only external variable is $_GET['video'] which would == '5ghfD1212332SDE3' for video 12.

I set error_reporting(E_ALL) but that hasn't produced anything unfortunately.

Thanks for your help/
<?php
 
session_start();
 
require('db-connection.php');
 
//Check user is logged in
if ($_SESSION['logged-id']!=0 && $_SESSION['logged-ip']==md5($_SERVER['REMOTE_ADDR'])) {
 
  //Has a video been requested
  if (isset($_GET['video'])) {
    $query = mysql_query("SELECT * FROM encVideos"); //Get all videos
    $video = mysql_real_escape_string($_GET['video']);
    while ($buffer = mysql_fetch_assoc($query)) {
      if (md5('5ghfD12'.$buffer['id'].'332SDE3') == $video) { //Remove misleading characters from videos id
	$group = mysql_fetch_assoc(mysql_query("SELECT * FROM groups WHERE id='".$buffer['group']."' LIMIT 1"));
	$file = "sfhs7ffEgf_eg24tgEGdhgdd234-3tEGdgddw/".$group['dir'].'/'.$buffer['file'];
	$video = explode('.',$buffer['file']); $preExt = '';
 
	//Find files extension
	for ($x=0;$x<(count($video)-1);$x++){$preExt .= $video[$x].'.';}
	$preExt = substr($preExt,0,-1); $ext = $video[(count($video)-1)];
	
	//Set Mime type		
	if (strtolower($ext)=='flv') {$mime = 'video/x-flv';}
	elseif (strtolower($ext)=='mov') {$mime = 'video/quicktime';}
	elseif (strtolower($ext)=='wmv') {$mime = 'video/x-ms-wmv';}
	
	//Show Video		
	header('Content-Description: Play Video');
	header('Content-Type: '.$mime);
	header('Content-Disposition: inline; filename='.$file);
	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($file));
	ob_clean();
	flush();
	readfile($file);
				
      }
    }
  }	
}
 
?>

Open in new window

0
 
Ray PaseurCommented:
Here, let's run this to see the exact content of the header data being sent to the browser.  Please post the output from running the script with these changes (marked with comments).  Thanks, ~Ray
<?php
 
// START OUTPUT BUFFERING
ob_start()
 
session_start();
 
require('db-connection.php');
 
//Check user is logged in
if ($_SESSION['logged-id']!=0 && $_SESSION['logged-ip']==md5($_SERVER['REMOTE_ADDR'])) {
 
  //Has a video been requested
  if (isset($_GET['video'])) {
    $query = mysql_query("SELECT * FROM encVideos"); //Get all videos
    $video = mysql_real_escape_string($_GET['video']);
    while ($buffer = mysql_fetch_assoc($query)) {
      if (md5('5ghfD12'.$buffer['id'].'332SDE3') == $video) { //Remove misleading characters from videos id
        $group = mysql_fetch_assoc(mysql_query("SELECT * FROM groups WHERE id='".$buffer['group']."' LIMIT 1"));
        $file = "sfhs7ffEgf_eg24tgEGdhgdd234-3tEGdgddw/".$group['dir'].'/'.$buffer['file'];
        $video = explode('.',$buffer['file']); $preExt = '';
 
        //Find files extension
        for ($x=0;$x<(count($video)-1);$x++){$preExt .= $video[$x].'.';}
        $preExt = substr($preExt,0,-1); $ext = $video[(count($video)-1)];
        
        //Set Mime type         
        if (strtolower($ext)=='flv') {$mime = 'video/x-flv';}
        elseif (strtolower($ext)=='mov') {$mime = 'video/quicktime';}
        elseif (strtolower($ext)=='wmv') {$mime = 'video/x-ms-wmv';}
        
        //Show Video            
        header('Content-Description: Play Video');
        header('Content-Type: '.$mime);
        header('Content-Disposition: inline; filename='.$file);
        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($file));
 
// SHOW THE CONTENTS OF THE OUTPUT BUFFER
$ob = ob_get_contents();
var_dump($ob);
die('TEST');
 
        ob_clean();
        flush();
        readfile($file);
                                
      }
    }
  }     
}
 
?>

Open in new window

0
 
Mr_SplashAuthor Commented:
Hi Ray,

I'm not seeing any reports, it's still showing windows media player taking up 100% of the window with status 'ready'.
0
 
Ray PaseurCommented:
I asked you to "Please post the output from running the script" and I don't see any output.  Maybe it would be easier for me to look at the process in action.  Please post the URL where I can see that script in action.  Thanks.
0
 
Mr_SplashAuthor Commented:
Hi Ray,

I'm saying there isn't any output. Windows Media Player is detecting that a wmv is being opened and is loading it's browser plugin.
0
 
Ray PaseurCommented:
Mr. Splash: We cannot help you if you won't respond to our requests.  I'll post an objection to closing this and ask that you go back to my last request.  If you've resolved this issue, please show us the resolution.  If not, please post the URL that we asked for, so we can see the script in action.  Best regards, ~Ray
0
 
Mr_SplashAuthor Commented:
Hi Ray,

Sorry for any confusion but I thought my last comment was a reply where I said that I could not provide the output because the windows media player is taking control of the browser.

I'm afraid I cannot provide a link as it's a secured site.

I've got around the problem by removing the session checking if statement. It works fine but it's not ideal as it's isn't 100% secure. So if you have any further suggestions they would be welcome.
0
 
ee_autoCommented:
Question PAQ'd, 500 points refunded, and stored in the solution database.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 5
Tackle projects and never again get stuck behind a technical roadblock.
Join Now