我的生产服务器是ubuntu Ubuntu 16.04.3 LTS,我在运行laravel 5.5:
/ var / www / forumb
我的公用文件夹在目录中:
/ var / www / forumb / public
用户上传图片,这些图片保存在:
/ var / www / forumb /公共/上传/图片
images文件夹中的images文件夹具有777权限,其中有使用封面的图像,并且这些图像从视图中正常显示
问题是从视图中看不到上载用户的图像,这些图像位于同一文件夹图像中
我可以直接从浏览器看到这样的封面图像:
用户图像
http://forumb.com/uploads/images/5fa7385e1542a31ab9c34419b4d914fe81a11449.jpeg
但是这些看不到,laravel返回404错误
从视图中可以看到的唯一图像是框架附带的图像,位于images文件夹中
在我将其他文件从Filezilla上传到服务器之前,其他所有内容都看不到
这只会在生产服务器上发生,在我的本地主机上一切正常
这是视图中的mi代码
<img class="card-img-top border-bot" src="{{ !is_null(user()->image) ? $profile_image : '/uploads/images/facebook-default-no-profile-pic.jpg' }}" class="img-fluid rounded mx-auto d-block" alt="{!! user()->nombre_empresa !!}">
这是我的控制器
public function index()
{
$perPage = 6;
$page = input('page', 1);
$baseUrl = config('app.url') . '/news-and-events';
$items = News::whereHas('photos')->with('photos')->active()->orderBy('active_from', 'DESC')->select('news.*')->get();
$profile_image = profile_image();
$total = $items->count();
// paginator
$paginator = new LengthAwarePaginator($items->forPage($page, $perPage), $items->count(),
$perPage, $page, ['path' => $baseUrl, 'originalEntries' => $total]);
// if pagination ajax
if (request()->ajax()) {
return response()->json(view('website.news_events.pagination')
->with('paginator', $paginator)
->render());
}
return $this->view('news_events.news_events')->with('paginator', $paginator)->with('profile_image', $profile_image);
}
profile_image()函数
function profile_image()
{
$image = user()->image;
$gender = user()->gender;
if ($image && strlen($image) > 5) {
return '/uploads/images/' . $image;
}
else {
return "/images/admin/$gender.png";
}
}
图片已正常上传但未显示
当您将上传的文件保存到磁盘时,Laravel会将文件放入storage/app/public
而不是public
。因此,您需要创建一个符号链接才能从Web上访问这些文件。
公共磁盘使用本地驱动程序并将这些文件存储在中
storage/app/public
。为了使它们可以从网上访问,您应该创建一个从public/storage
到的符号链接storage/app/public
要创建符号链接,可以使用
storage:link
Artisan命令:
php artisan storage:link
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句