Way too braindead this morning.... Simple parsing problem

Way too braindead this morning.... Simple parsing problem

am 20.01.2008 16:24:52 von Captain Dondo

I have a website that shows flash movies. I want to add a download
button that will download the same movie as a wmv file.

I can't for the life of me figure out how to do this....

The sendfile.php is invoked as

http://www.someserver.com/path/to/php/sendfile.php&image=htt p://
www.someserver.com/path/to/movies/xyz/movie.flv

what I need to do is to:

take basename of image, replace the .flv wih .wmv, use that as the
filename for 'Content-Disposition: attachment; filename='

replace the http://www.someserver.com/ part with the real path to the
file on the server and use that for the readfile($file) call

The only slighlty complicated thing is that the /xyz/ directory may be
present for some but not for others.

I've been going round and round and the only thing I can think of is that
I have been staring at code too long and haven't had enough coffee....

--Yan

Re: Way too braindead this morning.... Simple parsing problem

am 21.01.2008 00:40:46 von petersprc

You can use the script below:

Use PATH_INFO if your request is get.php/movie.flv or QUERY_STRING if
your request is get.php?movie.flv.


error_reporting(E_ALL | E_STRICT);

function sendWmv()
{
$file =3D substr(basename($_SERVER['QUERY_STRING']), 0, -4) . '.wmv';
$path =3D "/my/movies/$file";

if (!file_exists($path)) {
$path =3D "/my/movies/sub/$file";
if (!file_exists($path)) {
header("{$_SERVER['SERVER_PROTOCOL']} 404 Not Found");
header("Status: 404 Not Found");
echo ' EN">' .<br /> '404 Not Found

Not Found

' .
'The requested document was not found.';
return;
}
}

$sz =3D filesize($path);
header('Content-Type: video/x-ms-wmv');
header("Content-Length: $sz");
header('Content-Disposition: attachment; filename=3D"' .
basename($path) . "\"; size=3D$sz;");
readfile($path);
}

sendWmv();

?>

On Jan 20, 10:24 am, CptDondo wrote:
> I have a website that shows flash movies. I want to add a download
> button that will download the same movie as a wmv file.
>
> I can't for the life of me figure out how to do this....
>
> The sendfile.php is invoked as
>
> http://www.someserver.com/path/to/php/sendfile.phpâ„=91= 3Dhttp://www.s=
omeserver.com/path/to/movies/xyz/movie.flv
>
> what I need to do is to:
>
> take basename of image, replace the .flv wih .wmv, use that as the
> filename for 'Content-Disposition: attachment; filename=3D'
>
> replace thehttp://www.someserver.com/part with the real path to the
> file on the server and use that for the readfile($file) call
>
> The only slighlty complicated thing is that the /xyz/ directory may be
> present for some but not for others.
>
> I've been going round and round and the only thing I can think of is that
> I have been staring at code too long and haven't had enough coffee....
>
> --Yan