The Slim Framework support forum has moved to http://discourse.slimframework.com. This Tender forum is no longer maintained or monitored.

Responding with a file - question on response body

deleted-account's Avatar

deleted-account

06 Mar, 2012 03:16 PM

Hey,

a snippet of my non-Slim code is:

header('Content-Type: ' . $content_type);
header('Content-Disposition: attachment; filename="' . $basename . '"');
header("Content-length: $fsize");
header("Cache-control: private"); //use this to download instead of opening in browser
while(!feof($fd)) {
    $buffer = fread($fd, 2048);
    echo $buffer;
}

This doesn't play so nicely with Slim's $app->response() header.
http://www.slimframework.com/documentation/develop#response-header

I see that I could customize the header like:

$app->response()['Content-Type'] = $contentType;

However, I can't see how to adapt my fread code with Slim's $app->response()->body($fd).

Does Slim take care of feeding the file in parts to the browser?

  1. Support Staff 1 Posted by Josh Lockhart on 25 Mar, 2012 03:09 PM

    Josh Lockhart's Avatar

    The master branch does not. The develop branch does; there are several new streaming-methods in Slim that aim to improve Slim's support for streaming files, process output, or raw data to the HTTP client. However, this implementation is not final and may change before it is released in version 1.7.0. You can see more about the current implementation at:

    https://github.com/codeguy/Slim/issues/205#issuecomment-3309433

  2. Josh Lockhart closed this discussion on 25 Mar, 2012 03:09 PM.

Comments are currently closed for this discussion. You can start a new one.

Keyboard shortcuts

Generic

? Show this help
ESC Blurs the current field

Comment Form

r Focus the comment reply box
^ + ↩ Submit the comment

You can use Command ⌘ instead of Control ^ on Mac