oop中 限制文件类型和大小

 1 <?php
 2 /**
 3  * Created by IntelliJ IDEA.
 4  * User: jiabinwang
 5  * Date: 7/5/18
 6  * Time: 8:46 PM
 7  */
 8 
 9 namespace ElemeOpenApi\Efs;
10 
11 use ElemeOpenApi\Api\ContentService;
12 use ElemeOpenApi\Config\Config;
13 use ElemeOpenApi\Exception\BusinessException;
14 
15 class UploadVideoClient
16 {
17     private $config;
18     private $token;
19 
20     private $file_ext_list = array("MP4", "MOV");
21     private $file_max_size = 200;
22 
23     public function __construct($token, Config $config)
24     {
25         $this -> config = $config;
26         $this -> token = $token;
27     }
28 
29     /**
30      * 上传视频(封装ContentService中上传视频和获取efs配置接口)
31      *
32      * @param $file_path 视频文件本地地址
33      * @param $title 视频标题
34      * @param $desc 视频描述
35      * @param $video_type 视频类型
36      * @param $shop_id 店铺Id
37      * @return mixed
38      * @throws BusinessException 业务异常
39      */
40     public function upload_video_client($file_path, $title, $desc, $video_type, $shop_id) {
41         $file_extension = strtoupper(pathinfo(basename($file_path), PATHINFO_EXTENSION));
42 
43         if (!in_array($file_extension, $this -> file_ext_list)) {
44             throw new BusinessException("只支持mp4和mov格式的视频");
45         }
46 
47         if (filesize($file_path) > $this -> file_max_size * 1024 * 1024) {
48             throw new BusinessException("视频大小不能超过200M");
49         }
50 }

 

posted @ 2018-07-31 05:44  HaimaBlog  阅读(171)  评论(0编辑  收藏  举报