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