PHP code example of tourze / psr15-static-file-request-handler
1. Go to this page and download the library: Download tourze/psr15-static-file-request-handler library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
tourze / psr15-static-file-request-handler example snippets
use Tourze\PSR15StaticFileRequestHandler\StaticFileRequestHandler;
use Nyholm\Psr7\ServerRequest;
$publicPath = __DIR__ . '/public';
$handler = new StaticFileRequestHandler($publicPath);
$request = new ServerRequest('GET', '/test.txt');
$response = $handler->handle($request);
// Output response body
echo $response->getBody();
$request = $request->withHeader('Range', 'bytes=0-4');
$response = $handler->handle($request);
// Will return partial content (206) with specified range
use Symfony\Component\Filesystem\Filesystem;
$filesystem = new Filesystem();
$handler = new StaticFileRequestHandler($publicPath, $filesystem);
use Slim\App;
$app = new App();
$app->add(function ($request, $handler) {
$staticHandler = new StaticFileRequestHandler(__DIR__ . '/public');
return $staticHandler->handle($request);
});