zoukankan      html  css  js  c++  java
  • laravel中文件上传:

    laravel5.5版本:

    congfig下的filesystems.php中配置:uploads信息:

    'uploads' => [
           'driver' => 'local',
           'root' => storage_path('app/uploads')
      ],
    

    文件存储地址:storage/app/uploads

    上传文件表单必须定义:enctype="multipart/form-data"

    <form  enctype="multipart/form-data"></form>

    控制器:

    public function file(Request $request){
            $file=$request->file('source');
            //文件是否上传成功:
            if ($file->istValid()){
                //原文件名:
                $originalName=$file->getClientOriginalName();
                //扩展名:
                $ext=$file->getClientOriginalExtension();
                //MimeType:
                $type=$file->getClientMimeType();
                //临时绝对路径:
                $realPath=$file->getRealPath();
    
                $filename=date('Y-m-d-H-i-s').'-'.uniqid().'.'.$ext;
    
                $bool=Storage::dish('uploads')->put($filename,file_get_contents($realPath));
                var_dump($bool);
            }
    
        }
    

      

  • 相关阅读:
    arm64 boot
    python学习笔记
    字符编码问题详解
    Restful 架构设计
    调度器学习总结
    从0开始学习maven搭建spring+mybatis框架
    java内存管理
    linux 基础
    自学有感
    echart 图表显示技术
  • 原文地址:https://www.cnblogs.com/yiweiyihang/p/8471030.html
Copyright © 2011-2022 走看看