文件上传:获取信息 2020-09-07 17:57:17

获取上传的文件信息

public function uplode (Request $request){
        $isTure = $request->hasFile('name');
        if($isTure){
                $file = $request->file('name');
                dd($file);
        }
}

dd($file)的结果

-test: false
  -originalName: "0f6546b99eb41eb21036946e99b52371.mp4"
  -mimeType: "video/mp4"
  -error: 0
  #hashName: null
  path: "C:\Users\guang\AppData\Local\Temp"
  filename: "phpDF82.tmp"
  basename: "phpDF82.tmp"
  pathname: "C:\Users\guang\AppData\Local\Temp\phpDF82.tmp"
  extension: "tmp"
  realPath: "C:\Users\guang\AppData\Local\Temp\phpDF82.tmp"
  aTime: 2020-09-07 17:51:28
  mTime: 2020-09-07 17:51:28
  cTime: 2020-09-07 17:51:28
  inode: 0
  size: 1094425
  perms: 0100666
  owner: 0
  group: 0
  type: "file"
  writable: true
  readable: true
  executable: false
  file: true
  dir: false
  link: false
  linkTarget: "C:\Users\guang\AppData\Local\Temp\phpDF82.tmp"

如何获取上述信息?

除了头上的originalName外,其它的只需要在单词前加一个get

originalName的获取方式

$file->getClientOriginalName();

其它,如获取文件类型

$file = getMimeType();

获取大小

$file->getSize();

以此类推,十分简单。

  1. Laravel5.7
  2. 微信相关
  3. Mysql
  4. 前端开发
  5. 随记
  6. 写作素材
  7. 开发工具
  8. 互联网