zoukankan      html  css  js  c++  java
  • 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 ElemeOpenApiEfs;
    10 
    11 use ElemeOpenApiApiContentService;
    12 use ElemeOpenApiConfigConfig;
    13 use ElemeOpenApiExceptionBusinessException;
    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 }
    [Haima的博客] http://www.cnblogs.com/haima/
  • 相关阅读:
    02-05 flutter provider的使用
    02-04 flutter 构造函数总结
    02-03 flutter异步
    02-02dart语法
    02-01dart语法
    01-01 iOS内存对齐、内存对齐算法
    01-02 iOS kvo、kvc
    01-03 category 原理概述
    多线程编程 (2) -NSOperation
    IOS基本控件属性
  • 原文地址:https://www.cnblogs.com/haima/p/9393861.html
Copyright © 2011-2022 走看看