public function logo(Request $request)
{
$type = $request->post('type');
$file = $request->file();
var_dump($file);die();
$fileSize = 1024 * 1024 * 2;
// 获取表单上传文件
try {
validate(['logo' => 'fileSize:' . $fileSize . '|fileExt:jpg,png'])->check($file);
$files = $request->file("logo");
$savename = \think\facade\Filesystem::putFile($type, $files);
return json('uploads/' . $savename);
} catch (\think\exception\ValidateException $e) {
return json( $e->getMessage());
}
}
/**
* 保存新建的资源
*
* @param \think\Request $request
* @return \think\Response
*/
public function image(Request $request)
{
// 接收类型
$type = $request->post('type','goods');
// 接收数据
$file= $request->file("images");
// var_dump($file);die();
$fileSize = 1024 * 1024 * 2;
$error=[];
$success=[];
foreach ($file as $val){
try {
validate(['images' => 'fileSize:' . $fileSize . '|fileExt:jpg,png'])->check(['images'=>$val]);
$saveName = \think\facade\Filesystem::putFile($type, $val);
// 将成功后的路径保存到数组中
$success[]= 'uploads/' . $saveName;
dd($success);
}catch (\think\exception\ValidateException $e){
$error[]= [
'name' => $val->getOriginalName(),
'msg' => $e->getMessage()
];
}
}
// 组装返回数据的结果集
$data = [
'success' => $success,
'error' =>$error
];
dd($success);
// 返回数据
// return json($data);
}