all(),[ 'file' => 'required|max:'.config('tipask.upload.attach_size'), ]); if($validator->fails()){ return $this->ajaxError(10000,$validator->errors()->first('file')); } $file = $request->file('file'); $extension = $file->getClientOriginalExtension(); $filePath = 'attachments/'.gmdate("Y")."/".gmdate("m")."/".uniqid(str_random(8)).'.'.$extension; Storage::disk('local')->put($filePath,File::get($file)); return $this->ajaxSuccess([ 'url'=>route("website.attach.download",['name'=>str_replace("/","-",$filePath)]), 'name'=>$file->getClientOriginalName() ]); } public function download($name){ $attachFile = storage_path('app/'.str_replace("-","/",$name)); if(!is_file($attachFile)){ abort(404); } return response()->download($attachFile); } }