• laravel5.5文件上传


    /**
         * 上传文件
         * @param Request $request
         * @return array
         */
        public function upload(Request $request){
            $folder = 'Uploads/'.date('Ymd');
            if(!Storage::disk('public')->exists($folder)){
                Storage::makeDirectory($folder);
            }
            $files = $request->allFiles();//获取所有文档
            $fileid=[];
            foreach ($files as $file){
                if($file->isValid()) {
                    $newFileName = md5(microtime()) . '.' . $file->getClientOriginalExtension();
                    Storage::disk('public')->put($folder . '/' . $newFileName, file_get_contents($file));
                    //文件类型
                    $type = $file->getClientMimeType();
                    $size = $file->getSize();
                    $data = File::create(['filename' => $newFileName, 'filepath' => $folder,'md5' => '',  'mime' => $type, 'size' => $size]);
                    array_push($fileid,$data->id);
                }
            }
            //return response
            return ['fileid'=>implode(',',$fileid)];
        }


    /**
         * 删除文件
         * @param Request $request
         * @return array
         */
    public function destroy(Request $request)
        {
            $filename = explode(',',$request->input('filename'));
            $files = File::whereIn('filename',$filename)->get();
            $id = [];
            foreach ($files as $file){
                Storage::disk('public')->delete($file->filepath.'/'.$file->filename);
                $id[] = $file->id;
            }
            $result = File::destroy($id);
            if($result){
                return redirect()->back()->with('success','删除成功');
            }else{
                return redirect()->back()->with('error','删除失败');
            }
        }

  • 相关阅读:
    combotree的总结(这个好)
    Extjs下拉树代码测试总结
    ExtJs 3 自定义combotree
    项目中EXTjs中运用到的下拉树
    EXTJS下拉树ComboBoxTree参数提交及回显方法
    Extjs window组件 拖动统制
    extjs grid数据改变后刷新的实现
    获取 ext grid 选中行 对象
    ext:grid分页,列宽度自动填满grid宽度
    pringBoot2.0启用https协议
  • 原文地址:https://www.cnblogs.com/qq350760546/p/7930106.html
Copyright © 2020-2023  润新知