PHP code example of phramz / staticfiles-middleware
1. Go to this page and download the library: Download phramz/staticfiles-middleware 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/ */
phramz / staticfiles-middleware example snippets
use Symfony\Component\HttpFoundation\Request;
// your static files will be served from this folder
$webroot = '/var/www';
// if we cannot guess the files mime-type we'll use this default
$defaultMimetype = 'application/octed-stream';
// files with the following extensions will not be delivered. We'll get a 404 instead.
$exclude = ['php', 'key'];
// if true requests to non existing ressources will be passed to the next app in stack.
// if false the middleware will return a 404 response
$ignoreNotFound = true;
// create your application ... whatever it is e.g. Silex, Symfony2 etc.
$app = new Application();
// build the stack
$app = (new Stack\Builder())
->push(
'Phramz\Staticfiles\Middleware\HttpServer',
$webroot,
$defaultMimetype,
$exclude,
$ignoreNotFound
)
->resolve($app);
// dispatch the request
$request = Request::createFromGlobals();
$response = $app->handle($request);
$response->send();
// and shutdown
$app->terminate($request, $response);