我正在尝试将图片上传到我的网站,但它没有显示这是 HTML<div class="col-md-10"> <div class="post-image"> <canvas style="display: none" id="canvas-preview" style="overflow:hidden;"></canvas> <img id="img-preview" src="{{ url('backend/'). ($posts->preview_image?'/'. $posts->preview_image:'/post_preview/post-image.png')}}"> </div> <div class="m-b-10"> <a id="upload-submit" class="btn btn-warning btn-block btn-sm" onclick="file.click();"><i class="fa fa-upload"></i> Upload Picture </a> {{ Form::file('preview_image', ['class'=> 'btn btn-warning btn-block btn-sm','id'=>'file','style'=>'visibility:hidden']) }} </div> </div>控制器:public function create() { $this->authorize('create', Post::class); return \View::make('posts.edit') ->with('posts', new \App\Models\Post); }和模型:class Post extends Model{ const DEFAULT_PREVIEW_IMAGE = "post_preview/post-image.png"; /** * get preview image * @return mixed|string */ public function getPreviewImage() { return $this->show_preview_image?$this->preview_image:static::DEFAULT_PREVIEW_IMAGE; //return $this->preview_image; }}我尝试添加多个扩展像jpg,jpeg或gif在模型中,但问题仍然存在
2 回答
DIEA
TA贡献1820条经验 获得超2个赞
对于 Laravel 图像应该存储在存储文件夹中,或者您可以在存储文件夹中创建一个文件夹。您还需要创建符号链接
php artisan storage:link
这是将文件上传到存储文件夹的方法
if ($request->hasFile('file_name')) {
$file = $request->file('file_name');
$fileName = str_replace(' ', '-', $file->getClientOriginalName());
$uploadPath = storage_path('app/public/folder_name');
$path = $request->file('file_name')->move($uploadPath, $fileName);
$uploadPathFile = $fileName;
}
然后将路径保存到数据库。用于在刀片中显示图像
<img src="/storage/folder_name/{{$data->image}}" alt="No image available" class="img-thumbnail">
这里 $data->image 只是路径
- 2 回答
- 0 关注
- 305 浏览
添加回答
举报
0/150
提交
取消