• laravel文件上传


    一、视图文件代码

     <td>
            <input type="file" name="brand_logo" id="logo" size="45">
            <br>
            <span class="notice-span" style="display:block" id="warn_brandlogo">
              请上传图片,做为品牌的LOGO!
            </span>
     </td>

    二、控制器代码

    
    
    use IlluminateSupportFacadesStorage;
    use IlluminateHttpRequest;
    use IlluminateSupportFacadesDB;

    public
    function add(Request $request) { if($request->isMethod('POST')) { $data = $request->all(); $brand_logo = $request->file('brand_logo'); if($brand_logo->isValid()) { $ext = $brand_logo->getClientOriginalExtension();//后缀 $path = $brand_logo->getRealPath();//路径 $filename = date('Y-m-d-H-i-s').'.'.$ext;//重命名 Storage::disk('upload')->put($filename, file_get_contents($path));//上传 } $data['brand_logo'] = '/laravel56/public/brandpic/'.$filename; $res = DB::table('brand')->insert([ 'brand_name'=>$data['brand_name'], 'brand_logo'=>$data['brand_logo'], 'brand_desc'=>$data['brand_desc'], 'site_url'=>$data['site_url'], 'sort'=>$data['sort'], 'is_show'=>$data['is_show'] ]); if($res) { return redirect('Admin/Brand/brand_list'); } } }

    切记在config/filesystems.php中添加如下代码:

    'upload' => [
                'driver' => 'local',
                'root' => public_path('brandpic'),//brandpic是自己定义的文件保存目录
            ],
  • 相关阅读:
    selenium自动化测试实战——12306铁路官网范例
    mock接口开发——flask模块
    python调用接口——requests模块
    python操作redis
    python修改excel内容
    python读excel
    python发送邮件
    python写日志
    python的模块
    python写excel
  • 原文地址:https://www.cnblogs.com/wxy0126/p/10698304.html
Copyright © 2020-2023  润新知