Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
T
token
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
wallet
token
Commits
286ccde7
Commit
286ccde7
authored
Dec 30, 2020
by
shajiaiming
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'feature/optimize' into 'master'
fix See merge request
!435
parents
c293a438
8b47ab26
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
42 additions
and
0 deletions
+42
-0
OssController.php
api/controllers/OssController.php
+42
-0
No files found.
api/controllers/OssController.php
0 → 100644
View file @
286ccde7
<?php
namespace
api\controllers
;
use
Yii
;
use
OSS\OssClient
;
use
yii\web\UploadedFile
;
use
api\base\BaseController
;
class
OssController
extends
BaseController
{
protected
$accessKeyId
=
"LTAI4FxZ787zpBmjLmr6yMwA"
;
protected
$accessKeySecret
=
"5OMu030RFIE2KP3fNJrhVRTlVqBLaE"
;
protected
$endpoint
=
"http://oss-cn-shanghai.aliyuncs.com"
;
protected
$bucket
=
"bqbwallet"
;
public
function
actionUpload
()
{
$type
=
Yii
::
$app
->
request
->
post
(
'type'
,
''
);
$uploaded_file
=
UploadedFile
::
getInstanceByName
(
'file'
);
if
(
false
==
$uploaded_file
||
false
==
$type
)
{
$this
->
msg
=
'参数错误'
;
$this
->
code
=
-
1
;
goto
doEnd
;
}
$object
=
md5
(
date
(
'Y-m-d H:i:s'
)
.
$uploaded_file
->
tempName
)
.
'.'
.
$uploaded_file
->
extension
;
$filePath
=
$uploaded_file
->
tempName
;
$ossClient
=
new
OssClient
(
$this
->
accessKeyId
,
$this
->
accessKeySecret
,
$this
->
endpoint
);
$result
=
$ossClient
->
uploadFile
(
$this
->
bucket
,
'upload/'
.
(
empty
(
$type
)
?
''
:
$type
.
'/'
)
.
$object
,
$filePath
);
if
(
!
isset
(
$result
[
"info"
][
'url'
]))
{
$this
->
msg
=
'上传失败'
;
$this
->
code
=
-
1
;
goto
doEnd
;
}
$this
->
data
=
$result
[
"info"
][
'url'
];
doEnd
:
return
[
'code'
=>
$this
->
code
,
'msg'
=>
$this
->
msg
,
'data'
=>
$this
->
data
];
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment