请问图片上传的方法怎么写才能实现多图片同时选择上传
BEIBEI123 opened this issue · 2 comments
BEIBEI123 commented
目前我的写法是这样的,但是只支持单文件上传
public function wang_upload(Request $request){
if ($request->hasFile('wangEditorH5File') && $request->file('wangEditorH5File')->isValid()) {
$file = $request->file('wangEditorH5File');
$save=array();
$result = '/storage/'.Storage::disk("admin")->putFile("editor", $file);
$save[]=$result;
echo json_encode(array('errno'=>0,'data'=>$save));
} else {
echo json_encode(array('errno'=>1,'data'=>array(),'info'=>'no picture'));
}
}
z-song commented
用$request->allFiles()
获取所有上传文件对象
BEIBEI123 commented
可以了,谢谢,贴出了方便大家使用:
public function wang_upload(Request $request){
$save=array();
$all_file=$request->allFiles();
foreach ($all_file['wangEditorH5File'] as $key => $value) {
if ($value->isValid()) {
$result = '/storage/'.Storage::disk("admin")->putFile("editor", $value);
$save[]=$result;
}
}
echo json_encode(array('errno'=>0,'data'=>$save));
}
配置方法:
'wang-editor' => [
// 如果要关掉这个扩展,设置为false
'enable' => true,
// 编辑器的配置
'config' => [
'uploadImgServer' => '/api/wang_upload',
'uploadFileName' => 'wangEditorH5File[]'
]
],