Wenn Sie diese Bilder mit Slim zurückgeben, behalten Sie die Kontrolle in Ihren Händen: Sie können jederzeit die Route ändern oder Ordner hinzufügen. Sie können auch zusätzliche Header z. zum Zwischenspeichern.
$app->get('/assets/images/{pathToClientImage}', function($request, $response, $args) {
$pathToFile = $args['pathToClientImage'];
$containingFolder = '../clients_images/'; // the actual folder where files are stored
// since you want to omit file extension in the url, we'll have to find the file
$matches = glob($containingFolder.$fileName.'.*');
if ($matches) {
$clientImagePath = array_shift($matches); // let's grab the first file matching our mask
$clientImage = @file_get_contents($clientImagePath);
$finfo = new \Finfo(FILEINFO_MIME_TYPE);
$response->write($clientImage);
return $response->withHeader('Content-Type', $finfo->buffer($clientImage));
} else {
// if no matches found, throw exception that will be handled by Slim
throw new \Slim\Exception\NotFoundException($request, $response);
}
});
Bei URLs wie assets/images/client.png
(Dateierweiterung haben) ist akzeptabel für Sie, können Sie dies auf einfachere Art und Weise tun:
$app->get('/assets/images/{pathToClientImage}', function($request, $response, $args) {
$pathToFile = $args['pathToClientImage'];
$path = '../clients_images/'.$fileName;
$image = @file_get_contents($path);
$finfo = new \Finfo(FILEINFO_MIME_TYPE);
$response->write($image);
return $response->withHeader('Content-Type', $finfo->buffer($image));
});
Sie müssen dies mit zu '.htaccess' Datei hinzufügen Die Standardkonfigurationsordneranforderungen werden an Ihre index.php gesendet – jmattheis