【发布时间】:2021-12-26 19:01:48
【问题描述】:
我开发了一个 laravel 应用程序,它与图像一起在我的本地机器上完美运行。在部署到实时服务器时,图像不再可见。我正在使用共享主机,我的文件夹结构是这样的:public_html 包含上传等公共文件,main 包含用户不应该看到的剩余文件。这是我的控制器`公共功能
PortfolioAdd(){
return view('frontendbackend.portfoliosection.addportfolio');
}
public function PortfolioStore(Request $request){
$validatedData = $request->validate([
'title' => 'required:portfolio_sections,title',
'description' => 'required:portfolio_sections,description',
]);
$data = new PorfolioSection();
$data->title = $request->title;
$data->description = $request->description;
if ($request->file('image')) {
$file = $request->file('image');
$filename = date('YmdHi').$file->getClientOriginalName();
$file->move(public_path('upload/portfolio_images'),$filename);
$data['image'] = $filename;
}
$data->save();
`这是我的观点
<table id="example1" class="table table-bordered table-striped" style = "color:white">
<thead>
<tr>
<th width="5%" style = "color:white">SL</th>
<th style = "color:white">Title</th>
<th style = "color:white">Description</th>
<th style = "color:white">Image</th>
<th style = "color:white">Action</th>
</tr>
</thead>
<tbody>
@foreach($allData as $key => $portfolio )
<tr>
<td style = "color:white"> {{ $key+1 }} </td>
<td> {{ $portfolio->title }} </td>
<td> {{ $portfolio->description }} </td>
<td>
<img src="{{ (!empty($portfolio->image))? url('upload/portfolio_images/'.$portfolio->image):url('upload/no_image.jpg') }}" style="width: 60px; width: 60px;">
</td>
<td>
<a href="{{route('view.portfolio.edit', $portfolio->id)}}" class="btn btn-info">Edit</a>
<a href="{{route('view.portfolio.delete', $portfolio->id)}}" class="btn btn-danger" id="delete">Delete</a>
</td>
</tr>
@endforeach
</tbody>
<tfoot>
</tfoot>
</table>
【问题讨论】:
-
您是否将存储链接到
php artisan storage:link? -
不。请问我该怎么做。感谢您的回复
-
您将图像存储在 public_html 中?通常您将文件存储在存储文件夹中...