I'm using flowplay (flash) for embedded audio/video.
Initially I was using html5 w/ flowplay as fall back, but I stopped because flowplay is better than html5 on browsers that support html5.

Anyway - I also am making direct links to the media available as mp4/ogm and mp3/ogg.

The problem is browsers would often try to handle the media themselves instead of letting it download - so I made a wrapper php script that sends the right headers -

header("Content-type: " . $mime);
header("Content-Disposition: attachment; filename=" . $thispage);
header("Content-Transfer-Encoding: binary");

Browsers now do the right thing and let the media download, but there is no estimate on when the download the will complete.

I'm guessing I need to send a header with the content length for them to do that?

This is the function I use (stolen from web) to send the media:

define('CHUNK_SIZE', 1024*1024);
function readfile_chunked($filename, $retbytes = TRUE) {
    $buffer = '';
    $cnt =0;
     // $handle = fopen($filename, 'rb');
    $handle = fopen($filename, 'rb');
    if ($handle === false) {
       return false;
       }
    while (!feof($handle)) {
       $buffer = fread($handle, CHUNK_SIZE);
       echo $buffer;
       ob_flush();
       flush();
       if ($retbytes) {
          $cnt += strlen($buffer);
          }
       }
    $status = fclose($handle);
    if ($retbytes && $status) {
       return $cnt; // return num. bytes delivered like readfile() does.
       }
    return $status;
    }

Can someone suggest an improvement that will send the content length?
Looking around I see this used with images:

$length = strlen($imagedata);
header('Content-Length: '.$length);

Is that good enough?

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to