40 lines
1.2 KiB
PHP
40 lines
1.2 KiB
PHP
<?php
|
|
|
|
namespace app\admin\logic;
|
|
|
|
use app\common\basics\Logic;
|
|
use app\common\server\ConfigServer;
|
|
use app\common\server\storage\Driver as StorageDriver;
|
|
use think\facade\Config;
|
|
|
|
class MallNewsLogic extends Logic
|
|
{
|
|
private static $MAX_UPLOAD_SIZE = 50 * 1024 * 1024;
|
|
private static $FILE_PATH = 'mall_news/video';
|
|
|
|
public static function uploadVideo()
|
|
{
|
|
$file = request()->file('file');
|
|
if ($file->getSize() > self::$MAX_UPLOAD_SIZE) {
|
|
return ['code' => -1, 'msg' => '视频最大上传为50M'];
|
|
}
|
|
|
|
$config = [
|
|
'default' => ConfigServer::get('storage', 'default', 'local'),
|
|
'engine' => ConfigServer::get('storage_engine') ?? ['local'=>[]]
|
|
];
|
|
|
|
$StorageDriver = new StorageDriver($config);
|
|
$StorageDriver->setUploadFile('file');
|
|
if (!$StorageDriver->upload(self::$FILE_PATH)) {
|
|
return ['code' => -1, 'msg' => '上传错误'];
|
|
}
|
|
|
|
$fileName = $StorageDriver->getFileName();
|
|
if ($fileName) {
|
|
return ['code' => 1, 'msg' => '', 'data' => array('file' => Config::get('aliyunoss.domain') . self::$FILE_PATH . '/'. $fileName)];
|
|
}
|
|
|
|
return ['code' => -1, 'msg' => '上传失败'];
|
|
}
|
|
} |