ExcelController.php 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wenzhi
  5. * Date: 2019/2/18
  6. * Time: 5:16 PM
  7. */
  8. namespace App\Admin\Controllers;
  9. class ExcelController extends Controller{
  10. protected function upload(Request $request)
  11. {
  12. //图片存储方法。如果为图片存起来。如果不是返回''
  13. $fileCharater = $request->file('file');
  14. if ($fileCharater->isValid()) { //括号里面的是必须加的哦
  15. //如果括号里面的不加上的话,下面的方法也无法调用的
  16. $originalName = $fileCharater->getClientOriginalName(); // 文件原名
  17. $ext = $fileCharater->getClientOriginalExtension(); // 扩展名
  18. $realPath = $fileCharater->getRealPath(); //临时文件的绝对路径
  19. $type = $fileCharater->getClientMimeType(); // image/jpeg
  20. return $type;
  21. if (strpos($type, 'image') === false) {
  22. return $this->error('非法图片格式');
  23. }
  24. // 上传文件
  25. $filename = date('Y-m-d-H-i-s') . '-' . uniqid() . '.' . $ext;
  26. // 使用我们新建的uploads本地存储空间(目录)
  27. //这里的uploads是配置文件的名称
  28. $bool = Storage::disk('uploads')->put($filename, file_get_contents($realPath));
  29. if ($bool) {
  30. return $this->success('/storage/uploads/' . $filename);
  31. }
  32. }
  33. return $this->error();
  34. }
  35. }