implement a mechanism to return a file from a flysystem filesystem.
This commit is contained in:
parent
9584c0bdb5
commit
d61bbd5668
1 changed files with 16 additions and 0 deletions
|
|
@ -5,6 +5,7 @@ namespace Benzine\Controllers;
|
||||||
use Benzine\Controllers\Filters\Filter;
|
use Benzine\Controllers\Filters\Filter;
|
||||||
use Benzine\Exceptions\FilterDecodeException;
|
use Benzine\Exceptions\FilterDecodeException;
|
||||||
use Benzine\ORM\Abstracts\AbstractService;
|
use Benzine\ORM\Abstracts\AbstractService;
|
||||||
|
use League\Flysystem\Filesystem;
|
||||||
use Monolog\Logger;
|
use Monolog\Logger;
|
||||||
use Slim\Psr7\Request;
|
use Slim\Psr7\Request;
|
||||||
use Slim\Psr7\Response;
|
use Slim\Psr7\Response;
|
||||||
|
|
@ -111,4 +112,19 @@ abstract class AbstractController
|
||||||
->withStatus(404)
|
->withStatus(404)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected function returnFile(Filesystem $filesystem, string $filename) : Response{
|
||||||
|
$response = new Response();
|
||||||
|
if(!$filesystem->has($filename)){
|
||||||
|
return $this->pageNotFound();
|
||||||
|
}
|
||||||
|
|
||||||
|
//\Kint::dump($filesystem->getMimetype($assetName));exit;
|
||||||
|
|
||||||
|
$response->getBody()
|
||||||
|
->write($filesystem->read($filename));
|
||||||
|
;
|
||||||
|
|
||||||
|
return $response->withHeader("Content-type", $filesystem->getMimetype($filename));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue