我正在将图像上传到文件夹,并将数据保存到数据库。我该如何解决这个错误?错误在以下行中...
$property_features_image->move($destinationPath,$property_features_image);
public function store(Request $request)
{
$this->validate($request, [
'property_feature' => 'required|unique:property_features,property_features_name',
'property_icon' => 'required|image|mimes:jpg,png,jpeg|max:10240',
]);
$property_features_name = $request->property_feature;
$property_features_image = $request->file('property_icon');
$property_features_image = $property_features_image->getClientOriginalExtension();
$destinationPath = public_path('/images');
$property_features_image->move($destinationPath, $property_features_image);
DB::table('property_features')->insert([
'property_features_name' => $property_features_name,
'property_features_image' => $property_features_image,
]);
}
刀片
<form method="post" enctype="multipart/form-data" action="{{url('/admin/property-features')}}">
<div class="form-group">
<input type="hidden" value="{{csrf_token()}}" name="_token"/>
<label for="Property">Add Property Feature</label>
<input type="text" class="form-control" id="property_feature" name="property_feature"
placeholder="Enter Property Feature">
<label for="exampleFormControlFile1">Property Features's Icon</label>
<input type="file" class="form-control-file" id="property_icon" name="property_icon">
<?php echo($errors->first('property_feature', "<li class='ab' style='color:red;'>:message</li>"));?>
<?php echo($errors->first('property_icon', "<li class='ab' style='color:red;'>:message</li>"));?>
</div>
</form>
答案 0 :(得分:0)
此行:
$property_features_image = $property_features_image->getClientOriginalExtension();
将$property_features_image
变量分配为字符串值。
而且字符串不能有任何方法(您正在尝试调用move()方法)。
因此删除该行应该会有所帮助,但是随后您必须确保其他所有操作都没问题。在某处可能需要getClientOriginalExtension(),但我们看不到所有代码。