Sign In | Register Now About Bytes | Help | Site Map
Connecting Tech Pros Worldwide

Proxying a FLV file

Question posted by: adam.waterfield@gmail.com (Guest) on March 19th, 2008 02:35 PM
I have a script that 'proxys' a .flv file from a .htaccess protected
folder. The proxying script is being called by a Flash flv player in
the main webpage.

This script works wonderfully in Firefox and co, but not at all in
Internet Explorer.

Proxy Script minus all the authentication gubbins...

function getRemoteFileSize($url)
{
$parsed = parse_url($url);
$host = $parsed["host"];
$fp = @fsockopen($host, 80, $errno, $errstr, 20);
if(!$fp)return false;
else {
@fputs($fp, "HEAD $url HTTP/1.1\r\n");
@fputs($fp, "HOST: $host\r\n");
@fputs($fp, "Connection: close\r\n\r\n");
$headers = "";
while(!@feof($fp))$headers .= @fgets ($fp, 128);
}
@fclose ($fp);
$return = false;
$arr_headers = explode("\n", $headers);
foreach($arr_headers as $header) {
$s = "Content-Length: ";
if(substr(strtolower ($header), 0, strlen($s)) == strtolower($s))
{
$return = trim(substr($header, strlen($s)));
break;
}
}
}

$proxyURL = $_GET['url'];
header('Content-type: video/x-flv');
header('Content-length: '.getRemoteFileSize($proxyURL));
$src = fopen($proxyURL, 'r');
$out = fopen('php://output', 'w');
stream_copy_to_stream($src, $out);
fclose($src);
fclose($out);

As I said, this works fine in FF but not IE. Could anyone make any
suggestions as to why this could be? Perhaps some Header issues?

TIA
Toby A Inkster's Avatar
Toby A Inkster
Guest
n/a Posts
March 19th, 2008
06:05 PM
#2

Re: Proxying a FLV file
Join Bytes! wrote:
Quote:
I have a script that 'proxys' a .flv file from a .htaccess protected
folder. The proxying script is being called by a Flash flv player in the
main webpage.
>
This script works wonderfully in Firefox and co, but not at all in
Internet Explorer.


Try typing in the URL for the FLV via the proxy directly into each
browsers' address bars and saving the resulting files. Check the MD5 sum
of each and see if your script has introduced any differences between them.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 1 day, 19:35.]

The Semantic Web
http://tobyinkster.co.uk/blog/2008/03/09/sw/

adam.waterfield@gmail.com's Avatar
adam.waterfield@gmail.com
Guest
n/a Posts
March 19th, 2008
08:15 PM
#3

Re: Proxying a FLV file
Try typing in the URL for the FLV via the proxy directly into each
Quote:
browsers' address bars and saving the resulting files. Check the MD5 sum
of each and see if your script has introduced any differences between them.


Thanks for your response.

I have tried manually calling the proxy script with a file in the url
string. IE throws an error box window saying "Internet Explorer cannot
download script.php from localhost" and "Internet Explorer was not
able to open this Internet site - the site is either unavailable or
cannot be found. Try again later."

It would seem that IE doesn't like what this script is returning, yet
Firefox does? Seems odd. My first thoughts are the headers are playing
up - but yet with it been fine in FF it is a bit strange.

I was considering sticking these files in a DB opposed to a .htaccess
protected folder, but I don't fancy sticking 1.7gb of flv's into a DB!
(Especially when I would have the same issue, probably)

Rik Wasmus's Avatar
Rik Wasmus
Guest
n/a Posts
March 19th, 2008
08:25 PM
#4

Re: Proxying a FLV file
On Wed, 19 Mar 2008 21:14:57 +0100, Join Bytes!
<adam.waterfield@gmail.comwrote:
Quote:
Quote:
>Try typing in the URL for the FLV via the proxy directly into each
>browsers' address bars and saving the resulting files. Check the MD5 sum
>of each and see if your script has introduced any differences between
>them.

>
Thanks for your response.
>
I have tried manually calling the proxy script with a file in the url
string. IE throws an error box window saying "Internet Explorer cannot
download script.php from localhost" and "Internet Explorer was not
able to open this Internet site - the site is either unavailable or
cannot be found. Try again later."
>
It would seem that IE doesn't like what this script is returning, yet
Firefox does? Seems odd. My first thoughts are the headers are playing
up - but yet with it been fine in FF it is a bit strange.
>
I was considering sticking these files in a DB opposed to a .htaccess
protected folder, but I don't fancy sticking 1.7gb of flv's into a DB!
(Especially when I would have the same issue, probably)


I could very well imagine your 'getRemoteFileSize' function fails (no HEAD
allowed for instance), resulting in incorrect headers, which FF tries to
ignore for you but MSIE barfs over. Check wether there's a valid return
from that function, and only then include a Content-Length header.

It would be somewhat simpler to determine if you could give us the result
of the exact headers being sent by your script.
--
Rik Wasmus

adam.waterfield@gmail.com's Avatar
adam.waterfield@gmail.com
Guest
n/a Posts
March 19th, 2008
08:55 PM
#5

Re: Proxying a FLV file
I could very well imagine your 'getRemoteFileSize' function fails (no HEAD
Quote:
allowed for instance), resulting in incorrect headers, which FF tries to
ignore for you but MSIE barfs over. Check wether there's a valid return
from that function, and only then include a Content-Length header.


Thank you Rik. I disabled the said function and it works perfectly. I
only wish I had thought of that before, this has been frustrating me
for many hours.

Thanks for your all help guys - once again this newsgroup has been
more than helpful.

 
Not the answer you were looking for? Post your question . . .
189,938 Experts ready to help you find a solution.
Sign up for a free account, or Login (if you're already a member).

Latest Articles: Read & Comment
  • Didn't find the answer you were looking for?
    Post Your Question
  • Top Community Contributors