1
This commit is contained in:
parent
7a545ea88f
commit
59f3408b25
@ -492,50 +492,115 @@ class UploadController extends \app\controllers\Controller
|
|||||||
];
|
];
|
||||||
return $this->responseHandler($data);
|
return $this->responseHandler($data);
|
||||||
}
|
}
|
||||||
$action = "uploadfile";
|
|
||||||
$fileInfo = $this->uploadFile($action);
|
|
||||||
if ($rfmt == 'default') {
|
if (empty($_FILES['file']['name'])) {
|
||||||
if ($fileInfo["state"] == "SUCCESS") {
|
$data = [
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => "请选择要上传的文件"
|
||||||
|
];
|
||||||
|
return $this->responseHandler($data);
|
||||||
|
}
|
||||||
|
$type = $_FILES['file']['type'];
|
||||||
|
$explode = explode('/', $type);
|
||||||
|
$type = end($explode);
|
||||||
|
|
||||||
|
// 上传文件的目录
|
||||||
|
$upload_dir = "/web/uploads/file/";
|
||||||
|
|
||||||
|
if (!is_dir($upload_dir)) {
|
||||||
|
mkdir(\Yii::$app->basePath . '/web/uploads/file', 0777, true);
|
||||||
|
}
|
||||||
|
$file = md5($_FILES['file']['name']);
|
||||||
|
// 上传文件的全名
|
||||||
|
$upload_file = \Yii::$app->basePath . '/web/uploads/file/' . $file . $type;
|
||||||
|
// 将上传的文件从临时目录移动到指定目录
|
||||||
|
if (!move_uploaded_file($_FILES['file']['tmp_name'], $upload_file)) {
|
||||||
|
$data = [
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => "文件上传失败"
|
||||||
|
];
|
||||||
|
} else {
|
||||||
|
$oss = new Oss();
|
||||||
|
$file = '/web/upload/file/' . $file . '.png';
|
||||||
|
//上传文件目录
|
||||||
|
$oss_data = $oss->upload($upload_file, $file);
|
||||||
|
if ($oss == false) {
|
||||||
|
$data = [
|
||||||
|
'code' => 1,
|
||||||
|
'msg' => "文件上传失败"
|
||||||
|
];
|
||||||
|
} else {
|
||||||
$data = [
|
$data = [
|
||||||
'code' => 0,
|
'code' => 0,
|
||||||
'msg' => 'success',
|
'msg' => 'success',
|
||||||
'data' => [
|
'data' => [
|
||||||
'url' => $fileInfo['url'],
|
'url' => $oss_data,
|
||||||
'extension' => $fileInfo["type"],
|
|
||||||
'size' => $fileInfo["size"],
|
|
||||||
'type' => $this->getFileType(trim($fileInfo['type'], "."))
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
} else {
|
|
||||||
$data = [
|
|
||||||
'code' => 1,
|
|
||||||
'msg' => $fileInfo["state"]
|
|
||||||
];
|
|
||||||
}
|
|
||||||
} else if ($rfmt == 'wangeditor') {
|
|
||||||
if ($fileInfo["state"] == "SUCCESS") {
|
|
||||||
$data = [
|
|
||||||
'errno' => 0,
|
|
||||||
'message' => 'success',
|
|
||||||
'data' => [
|
|
||||||
'url' => $fileInfo['url'],
|
|
||||||
'alt' => '',
|
|
||||||
'href' => '',
|
|
||||||
'extension' => $fileInfo["type"],
|
|
||||||
'size' => $fileInfo["size"],
|
|
||||||
'type' => $this->getFileType(trim($fileInfo['type'], "."))
|
|
||||||
]
|
|
||||||
];
|
|
||||||
} else {
|
|
||||||
$data = [
|
|
||||||
'errno' => 1,
|
|
||||||
'message' => $fileInfo["state"]
|
|
||||||
];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return $this->responseHandler($data);
|
return $this->responseHandler($data);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// //上传文件
|
||||||
|
// public function actionFile($rfmt = 'default')
|
||||||
|
// {
|
||||||
|
// if (!\Yii::$app->request->isPost) {
|
||||||
|
// $data = [
|
||||||
|
// 'code' => 1,
|
||||||
|
// 'msg' => "Invalid Request"
|
||||||
|
// ];
|
||||||
|
// return $this->responseHandler($data);
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// $action = "uploadfile";
|
||||||
|
// $fileInfo = $this->uploadFile($action);
|
||||||
|
// if ($rfmt == 'default') {
|
||||||
|
// if ($fileInfo["state"] == "SUCCESS") {
|
||||||
|
// $data = [
|
||||||
|
// 'code' => 0,
|
||||||
|
// 'msg' => 'success',
|
||||||
|
// 'data' => [
|
||||||
|
// 'url' => $fileInfo['url'],
|
||||||
|
// 'extension' => $fileInfo["type"],
|
||||||
|
// 'size' => $fileInfo["size"],
|
||||||
|
// 'type' => $this->getFileType(trim($fileInfo['type'], "."))
|
||||||
|
// ]
|
||||||
|
// ];
|
||||||
|
// } else {
|
||||||
|
// $data = [
|
||||||
|
// 'code' => 1,
|
||||||
|
// 'msg' => $fileInfo["state"]
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
// } else if ($rfmt == 'wangeditor') {
|
||||||
|
// if ($fileInfo["state"] == "SUCCESS") {
|
||||||
|
// $data = [
|
||||||
|
// 'errno' => 0,
|
||||||
|
// 'message' => 'success',
|
||||||
|
// 'data' => [
|
||||||
|
// 'url' => $fileInfo['url'],
|
||||||
|
// 'alt' => '',
|
||||||
|
// 'href' => '',
|
||||||
|
// 'extension' => $fileInfo["type"],
|
||||||
|
// 'size' => $fileInfo["size"],
|
||||||
|
// 'type' => $this->getFileType(trim($fileInfo['type'], "."))
|
||||||
|
// ]
|
||||||
|
// ];
|
||||||
|
// } else {
|
||||||
|
// $data = [
|
||||||
|
// 'errno' => 1,
|
||||||
|
// 'message' => $fileInfo["state"]
|
||||||
|
// ];
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return $this->responseHandler($data);
|
||||||
|
// }
|
||||||
|
|
||||||
//上传视频
|
//上传视频
|
||||||
public function actionVideoFile()
|
public function actionVideoFile()
|
||||||
{
|
{
|
||||||
|
|||||||
BIN
web/uploads/file/588e8d87b845713e8ac5df30269a908bmp4
Normal file
BIN
web/uploads/file/588e8d87b845713e8ac5df30269a908bmp4
Normal file
Binary file not shown.
Loading…
x
Reference in New Issue
Block a user