上传视频
@param $videoPath
@return bool|mixed
@throws \yii\web\HttpException
348988
public function uploadVideo($videoPath)
    {
        $result = $this->httpPost(self::WECHAT_VIDEO_UPLOAD_URL, [
            'media' => $this->uploadFile($videoPath)
        ], [
            'access_token' => $this->getAccessToken()
        ]);
        return isset($result['media_id']) ? $result : false;
    }
532752
public function moveTo(string $fullPath) : IFile
    {
        if ($this->moveCallback) {
            return call_user_func($this->moveCallback, $fullPath);
        }

        return $this->file;
    }
125208
public static function upload($filePath, $userid = 0,$title = '', $desc = '', $magicContext = '') {

        // $filePath = realpath($filePath);

		if (!file_exists($filePath)) {
			return array('httpcode' => 0, 'code' => self::VIDEO_FILE_NOT_EXISTS, 'message' => 'file '.$filePath.' not exists', 'data' => array());
		}

		$expired = time() + self::EXPIRED_SECONDS;
		$url = self::generateResUrl($userid);
		$sign = Auth::appSign($url, $expired);

		$data = array(
            'FileContent' => '@'.$filePath,
        );
        if ($title) {
        	$data['Title'] = $title;
        }
        if ($desc) {
        	$data['Desc'] = $desc;
        }
		if ($magicContext) {
        	$data['MagicContext'] = $magicContext;
        }

        $req = array(
            'url' => $url,
            'method' => 'post',
            'timeout' => 10,
            'data' => $data,
            'header' => array(
                'Authorization:'.$sign,
            ),
        );

		$rsp = Http::send($req);
		$info = Http::info();
		$ret = json_decode($rsp, true);

		if ($ret) {
			if (0 === $ret['code']) {
				return array(
						'httpcode' => $info['http_code'],
						'code' => $ret['code'],
						'message' => $ret['message'],
						'data' => array(
								'url' => $ret['data']['url'],
								'downloadUrl' => $ret['data']['download_url'], 'fileid' => $ret['data']['fileid'],
								'cover_url' => (isset($ret['data']['cover_url']) ? $ret['data']['cover_url'] : ""),
								)
							);
			} else {
				return array(
					'httpcode' => $info['http_code'],
					'code' => $ret['code'],
					'message' => $ret['message'],
					'data' => array()
				);
			}
		} else {
			return array(
					'httpcode' => $info['http_code'],
					'code' => self::VIDEO_NETWORK_ERROR,
					'message' => 'network error', 'data' => array()
				);
		}
	}
699594
private function moveFile()
        {
            $files = $this->files;
            
            if ($this->formats != "" && !in_array($this->fileExt, $this->formats))
            {
                $formats = implode(',', $this->formats);
                $message = "您上传的文件" . $files["name"] . "是" . $this->fileExt . "格式的，系统不允许上传，您只能上传" . $formats . "格式的文件。";
                $this->message($message);
                
                return false;
            }

            if ($files["size"] / 1024 > $this->maxSize)
            {
                $message = "您上传的 " . $files["name"] . "，文件大小超出了系统限定值" . $this->maxSize . " KB，不能上传。";
                $this->message($message);
                
                return false;
            }

            if (!$this->cover) //当不能覆盖时
            {
                if(file_exists($this->savePath.$this->saveName)) //有相同的文件存在
                {
                    $this->message($this->saveName . $this->errors['same_file']);
                    
                    return false;
                }
            }

            if (!@move_uploaded_file($files["tmp_name"], iconv("utf-8", "gbk", $this->savePath . $this->saveName)))
            {                
                switch($files["errors"])
                {
                    case '0':
                        $message = "文件上传成功";
                        break;
                    
                    case '1':
                        $message = "上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值";
                        break;
                    
                    case '2':
                        $message = "上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值";
                        break;
                    
                    case '3':
                        $message = "文件只有部分被上传";
                        break;
                    
                    case '4':
                        $message = "没有文件被上传";
                        break;
                    
                    case '6':
                        $message = "找不到临时目录";
                        break;
                    
                    case '7':
                        $message = "写文件到硬盘时出错";
                        break;
                    
                    case '8':
                        $message = "某个扩展停止了文件的上传";
                        break;
                    
                    case '999':
                    default:
                        $message = "未知错误，请检查文件是否损坏、是否超大等原因。";
                        break;
                }

                $this->message($message);
                
                return false;
            }
            
            @unlink($files["tmp_name"]); //删除临时文件
            
            return true;
        }
1009003
public function extractImageFromVideo($filePath, $timeFrame = 1)
    {
        $pathInfo = pathinfo($filePath);
        $extractedImagePath = $pathInfo['dirname'] . DIRECTORY_SEPARATOR
            . time() . $pathInfo['basename'] . '-' . $timeFrame . '.jpg';

        $video = $this->ffmpeg->open($filePath);
        $video->frame(TimeCode::fromSeconds($timeFrame))->save($extractedImagePath);

        return $extractedImagePath;
    }
1162995
public function importFile($localPath, FileInterface $folder = null)
    {
        if(!$folder->isDir()){
            throw new RuntimeException('Files can only be moved into directories');
        }
        //$fileName = $uploadedFile->getClientOriginalName();

        $fileName = basename($localPath);

        $targetPath = $folder ? $folder->getPath() . "$fileName" : $fileName;

        $this->files->move($localPath, $targetPath);

        $absPath = $this->mapper->absolutePath($targetPath);

        $file = $this->createFromPath($targetPath);

        if ($folder) {
            $file->setDir($folder);
            $folder->addChild($file);
        }

        $this->save($file);

        return $file;
    }
921841
public function actionUpload() 
	{
		$runtimePath = Yii::app()->runtimePath;

		// Upload and extract yii module
		if(isset($_FILES['module_file'])) {
			$fileName = CUploadedFile::getInstanceByName('module_file');
			echo $fileName->type;

			if(strpos($fileName->type, 'zip') !== false) {
				if($fileName->saveAs($runtimePath.'/'.$fileName->name)) {
					$zip        = new ZipArchive;
					$zipFile    = $zip->open($runtimePath.'/'.$fileName->name);
					$extractTo  = explode('.', $fileName->name);
					@chmod($runtimePath.'/'.$fileName->name, 0777);

					if($zipFile == true) {
						if($zip->extractTo(Yii::getPathOfAlias('application.modules'))) {
							Utility::chmodr(Yii::getPathOfAlias('application.modules').'/'.$extractTo[0], 0777);
							$this->redirect(array('manage','type'=>'all'));
							Yii::app()->user->setFlash('success', Yii::t('phrase', 'Module sukses diextract.'));
						}
						$zip->close();
						Utility::recursiveDelete($runtimePath.'/'.$fileName->name);
					}

				} else
					Yii::app()->user->setFlash('error', Yii::t('phrase', 'Gagal mengupload file.'));	
			} else
				Yii::app()->user->setFlash('error', Yii::t('phrase', 'Hanya file .zip yang dibolehkan.'));
		}
		
		$this->dialogDetail = true;
		$this->dialogGroundUrl = Yii::app()->controller->createUrl('manage');
		$this->dialogWidth = 500;
		
		$this->pageTitle = Yii::t('phrase', 'Upload Module');
		$this->pageDescription = '';
		$this->pageMeta = '';
		$this->render('admin_upload');
	}
1336036
public function updateMedia($mediaPath, $type)
    {
        $result = $this->httpPost(self::WECHAT_MEDIA_UPLOAD_PREFIX, [
            'media' => $this->uploadFile($mediaPath)
        ], [
            'access_token' => $this->getAccessToken(),
            'type' => $type
        ]);
        return isset($result['media_id']) ? $result : false;
    }
1182309
public function save($savepath) {
		$result = move_uploaded_file($this->stored_filename, $savepath);
		if ($result === true) {
			$this->stored_filename = $savepath;
			return true;
		} else {
			return false;
		}
	}
1080579
public function loadYamlFile($filePath)
    {
        if (file_exists($filePath)) {
            $this->loadYaml(file_get_contents($filePath));

            return $this;
        }

        return $this;
    }
426204
public function loadFile($filePath)
    {
        if (strrpos($filePath, $this->extension) !== false) {
            $fileKey = str_replace([$this->path, $this->extension, DIRECTORY_SEPARATOR], ['', '', '-'], $filePath);
            $this->store(camelcase($fileKey), new SplFileInfo($filePath));
        }
    }
240108
public function addMaterial($mediaPath)
    {
        $result = $this->wechat->httpPost(self::WECHAT_MATERIAL_ADD_PREFIX, [
            'media' => $this->wechat->uploadFile($mediaPath)
        ], [
            'access_token' => $this->getAccessToken()
        ]);
        return isset($result['errcode']) && !$result['errcode'] ? $result['data'] : false;
    }
659337
public function loadFile($filePath)
    {
        if ($filePath instanceof \SplFileInfo) {
            $filePath = $filePath->getRealPath();
        }

        if (is_file($filePath)) {
            return $this->loadString(file_get_contents($filePath));
        }

        return false;
    }
1289213
public function post($requestPath, array $postData)
    {
        $requestUri = sprintf('%s/%s', $this->baseUri, $requestPath);

        return $this->responseHandler(
            'POST',
            $requestPath,
            $this->httpClient->post($requestUri, $postData)
        );
    }
697501
public function uploadShopImage($filePath, $fileName = null)
    {
        $fileName === null && $fileName = pathinfo($filePath, PATHINFO_BASENAME);
        $result = $this->httpRaw(self::WECHAT_SHOP_IMAGE_UPLOAD_URL .
            'access_token=' . $this->getAccessToken() . '&filename=' . $fileName, file_get_contents($filePath));
        return isset($result['errmsg']) && $result['errmsg'] == 'success' ? $result['image_url'] : false;
    }
1164856
public function storeTemporaryVideo (Video $video)
    {
        return $this
            ->storeVideo(false, $video)
            ->withExpiresDate(new \DateTime('@' . (time() + 172800))); // @todo: change to use the JSON's created_at property.
    }
7937
protected function uploadTemp($filePath, $type)
    {
        $url = sprintf(self::MEDIA_TEMP_UPLOAD_URL, $this->getAccessTokenString(), $type);
        $client = $this->getHttpClient();
        $client->setUrl($url);
        $client->setMethod(Client::METHOD_UPLOAD);

        $basename = basename($filePath);

        $client->setPostDataArray([ 'media'          => curl_file_create($filePath),
                                    'filename'      => $basename,
                                    'filelength'    => filesize($filePath),
                                    'content-type'  => $this->getUpLoadContentType($type),
                                    'hack'          => '',
                                    ]);
        if (!$client->exec()) {
            throw new Exception("call send custom service message fail");
        }

        $result = json_decode($client->getResponse(), true);

        if (isset($result['errcode'])) {
            throw new Exception("error response for upload Temp info " . $result['errcode'] . ' ' . $result['errmsg']);
        }

        return $result;
    }