【发布时间】:2015-05-17 12:12:37
【问题描述】:
我正在学习 Laravel 5,但遇到了问题。
如果我尝试像这样将图像传递给路线
http:://localhost/someImage.jpg
路线是这样的:
Route::get('/{filename}', function($filename){
$img = Image::make(storage_path($filename))->resize(50, 50);
return $img->response('jpg');
});
它返回请求的资源 someImage.jpg 在此服务器上找不到。
如果我这样称呼它
http:://localhost/someImage
我的路线是
Route::get('/{filename}', function($filename){
$img = Image::make(storage_path($filename . ('.jpg')))->resize(50, 50);
return $img->response('jpg');
});
可以显示图片。
我怎样才能使第一个示例工作?
我不确定,但我认为它试图直接访问图像而不是将其传递给路由,并且我需要更改一些配置以防止它。也许在htaccess中?
.htaccess 内容
<IfModule mod_rewrite.c>
<IfModule mod_negotiation.c>
Options -MultiViews
</IfModule>
RewriteEngine On
# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ /$1 [L,R=301]
# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]
【问题讨论】:
-
向我们展示您的
.htaccess文件。
标签: php .htaccess laravel laravel-5