我希望更改我的表单,使其能够一次上传多张图片,以下是我目前的代码:
表单中的部分内容:
感谢您的帮助!
表单中的部分内容:
{!! Form::open(['action' => 'PostsController@store', 'method' => 'POST', 'enctype' => 'multipart/form-data']) !!}
{{Form::file('stock_image')}}
我的控制器:
if($request->hasFile('stock_image')){
$filenameWithExt = $request->file('stock_image')->getClientOriginalName();
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
$extension = $request->file('stock_image')->getClientOriginalExtension();
$fileNameToStore= $filename.'_'.time().'.'.$extension;
$path = $request->file('stock_image')->storeAs('public/images', $fileNameToStore);
} else {
$fileNameToStore = 'noimage.jpg';
}
感谢您的帮助!
$request->file('stock_image')
时,您将获得一个文件数组(注意:如果您以这种方式操作,我建议将名称更改为stock_images
)。 - Mark Walet