forked from phly/psr7examples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcopy-stream.php
30 lines (25 loc) · 983 Bytes
/
copy-stream.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
<?php
/**
* Example demonstrating returning a file as a stream.
*
* Essentially, point your Phly\Http\Stream at a file, pass it to a response,
* and return the response; if you can provide proper headers, do it.
*
* @copyright Copyright (c) 2015 Matthew Weier O'Phinney (https://mwop.net)
* @license http://opensource.org/licenses/BSD-2-Clause BSD-2-Clause
* @codingStandardsIgnoreFile
*/
use Phly\Http\Response;
use Phly\Http\Server;
use Phly\Http\Stream;
require __DIR__ . '/../vendor/autoload.php';
$server = Server::createServer(function ($request, $response, $done) {
// Cuervo was our original Basset Hound; this was her in her natural habitat.
$image = __DIR__ . '/cuervo.jpg';
return (new Response())
->withHeader('Content-Type', 'image/jpeg')
->withHeader('Content-Length', (string) filesize($image))
->withBody(new Stream($image));
return $response;
}, $_SERVER, $_GET, $_POST, $_COOKIE, $_FILES);
$server->listen();