PHP code example of mycodebox / slim-file-response-plus
1. Go to this page and download the library: Download mycodebox/slim-file-response-plus 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/ */
mycodebox / slim-file-response-plus example snippets
// path returns a PNG
$app->get('/test/image', function ($request, $response) {
$filePath = $_SERVER["DOCUMENT_ROOT"]. "/path/to/your/image/file.png";
return \MyCodebox\SlimFileResponse\FileResponse::getResponse($response, $filePath);
});
// path returns a PDF file
$app->get('/test/pdf', function ($request, $response) {
$filePath = $_SERVER["DOCUMENT_ROOT"]. "/path/to/your/pdf/file.pdf";
return mhndev\slimFileResponse\FileResponse::getResponse($response, $filePath, 'myDocument');
});
// path returns the given `filename` attribute
$app->get('/test/file/{filename}', function ($request, $response) {
$fileName = $request->getAttribute('filename');
$filePath = $_SERVER["DOCUMENT_ROOT"]. "/path/to/your/file/$fileName";
return \MyCodebox\SlimFileResponse\FileResponse::getResponse($response, $filePath);
});
// path returns a `file_not_found.png` in case the given file is not found
$app->get('/test/file/{filename}', function ($request, $response) {
$notFound = $_SERVER["DOCUMENT_ROOT"]. "/path/to/your/image/file_not_found.png";
$fileName = $request->getAttribute('filename');
$filePath = $_SERVER["DOCUMENT_ROOT"]. "/path/to/your/file/$fileName";
$caching = true; // default is false - withLastModified( filemtime(fileName) )
return \MyCodebox\SlimFileResponse\FileResponse::getResponse($response, $filePath, null, $notFound, $caching);
});
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.