Ticket Details

provide a means to use fpassthru() in views

RFC Ticket (closed)

When rendering media files, it would be desirable to be able to use fpassthru(). My understanding of the current architecture -- which might be wrong ;-) -- is only based on the docs drafts, but if I get this right the dispatcher creates an output buffer and ships the request to the Media class, where headers are sent and so forth.

Now, consider a 100MB video stored in a database, and picture what happens when using the following two code snippets:

{{{
<?php
$name = './img/ok.png';
$fp = fopen($name, 'rb');

header("Content-Type: image/png");
header("Content-Length: " . filesize($name));
fpassthru($fp);
exit;
?>

<?php
$db = new PDO('odbc:SAMPLE', 'db2inst1', 'ibmdb2');
$stmt = $db->prepare("select contenttype, imagedata from images where id=?");
$stmt->execute(array($_GET['id']));
$stmt->bindColumn(1, $type, PDO::PARAM_STR, 256);
// fetch a stream, rather than the data itself
$stmt->bindColumn(2, $lob, PDO::PARAM_LOB);
$stmt->fetch(PDO::FETCH_BOUND);

header("Content-Type: $type");
fpassthru($lob);
exit;
?>
}}}

It would be nice if we extended the API so a file pointer could be returned by the Controller, e.g. an `fpassthru` param which, when set, proceeds to `fpassthru()` the resource after headers are sent and before exiting.
on 08.28.10 reported by: ddebernardy owned by: nate

Updates

on 09.30.10 by nate
You can create a handler that does this. Check out the docs for Media::type().
(works-for-me) on 10.12.10 by nate
  • owner was changed to nate
  • status was changed to closed
  • resolution was changed to works-for-me
This app contains two different examples of how you'd want to approach the above:

http://dev.lithify.me/photoblog/source