我正在使用图像干预包调整图像的大小。调整大小后,我已经成功上传了许多文件。但是现在不起作用了。 每次我尝试上传图片时,都会显示错误“图片上传失败”。 我也增加了配置文件中的文件大小,但没有解决问题。
我的控制器:
$file = \Request::file('feature_image');
if (!$file == "") {
// validate the posted data
$validator = $request->validate([
'feature_image' => 'required|mimes:jpeg,jpg,png|max:2048'
]);
$path = storage_path().'/images/blog/'.$blog->featured_image;
// delete the previous featured image
@unlink($path);
$extension = $file->getClientOriginalExtension();
$orginalFileName = $file->getClientOriginalName();
$filename = pathinfo($orginalFileName , PATHINFO_FILENAME).'_'.rand();
$org_name = $filename.'.'.$extension;
// $thumbnail = Image::make($file->getRealPath());
// now you are able to resize the instance
// $thumbnail->resize(350, 233)->save(storage_path().'/images/blog/thumbnail/'. $org_name);
$featuredImage = Image::make($request->file('feature_image')->getRealPath());
// now you are able to resize the instance
$featuredImage->resize(730, 487)->save(storage_path().'/images/blog/'. $org_name);
// $file->move(storage_path().'/images/blog',$org_name);
$blog->featured_image = $org_name;
$blog->save();
}
我的HTML:
<form class="form-floating" action="{{url('edit_blog/'.request()->id)}}" method="post" enctype="multipart/form-data">
{{csrf_field()}}
<label for="exampleInputFile"><b>Feature Image<span class="post-required">*</span></b></label>
<input type="file" name="feature_image" id="feature_image">
</form>
我不知道实际的问题是什么。我已经花了很多时间解决这个问题,如果有人能在这方面帮助我,我将不胜感激。 谢谢,
注意:程序包可以在我的本地主机上正常工作。