• PHP 文件上传常规格式


    PHP 文件上传常规格式

    *相关扩展一定要打开

    客户端代码:

    <form action="{{ route('admin.article.store') }}"enctype="multipart/form-data" method="post" class="form form-horizontal" id="form-member-add"> 
        <input type="file" name="pic"> 
    </form>

    服务器端代码:

    AddArtRequest为自定义验证

    public function store(AddArtRequest $request)
        {
            //文件上传
            //默认封面图片
            $pic = config('upload.pic');
    
            if($request->hasFile('pic'))
            {
                //上传
                //参数2 配置的节点 名称 article需要在filesystems.php 文件中自定义
                $result = $request->file('pic')->store('','article');
    //            dump($result);
                $pic = '/uploads/article/'.$result;
    //            dd($pic);
            }
            $post = $request->except('_token');
            $post['pic'] = $pic;
            //添加 入库操作
            Article::create($post);
            return redirect(route('admin.article.index'));
        }

    filesysts.php

    'disks' => [
    
            'local' => [
                'driver' => 'local',
                'root' => storage_path('app'),
            ],
    
            //文章上传的封面
            'article'=>[
                'driver'=>'local',
                'root'=>public_path('uploads/article'),
            ],
            
            
            
            'public' => [
                'driver' => 'local',
                'root' => storage_path('app/public'),
                'url' => env('APP_URL').'/storage',
                'visibility' => 'public',
            ],
    
            's3' => [
                'driver' => 's3',
                'key' => env('AWS_ACCESS_KEY_ID'),
                'secret' => env('AWS_SECRET_ACCESS_KEY'),
                'region' => env('AWS_DEFAULT_REGION'),
                'bucket' => env('AWS_BUCKET'),
                'url' => env('AWS_URL'),
            ],
    
        ],
  • 相关阅读:
    UVa532 Dungeon Master 三维迷宫
    6.4.2 走迷宫
    UVA 439 Knight Moves
    UVa784 Maze Exploration
    UVa657 The die is cast
    UVa572 Oil Deposits DFS求连通块
    UVa10562 Undraw the Trees
    UVa839 Not so Mobile
    327
    UVa699 The Falling Leaves
  • 原文地址:https://www.cnblogs.com/zqblog1314/p/12708431.html
Copyright © 2020-2023  润新知