Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵增煜
/
tzt-admin
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
4e8109d8
authored
Nov 19, 2024
by
赵增煜
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
上传图片修改
parent
34f179db
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
6 additions
and
40 deletions
+6
-40
app/Api/Controllers/DoctorController.php
+3
-19
app/Api/Controllers/PharmacistController.php
+3
-21
No files found.
app/Api/Controllers/DoctorController.php
View file @
4e8109d8
...
@@ -39,31 +39,15 @@ public function upload(Request $request)
...
@@ -39,31 +39,15 @@ public function upload(Request $request)
// 获取上传的图片
// 获取上传的图片
if
(
$request
->
hasFile
(
'image'
))
{
if
(
$request
->
hasFile
(
'image'
))
{
// 获取图片文件
$path
=
Storage
::
putFile
(
'license-images'
,
$request
->
file
(
'image'
));
$image
=
$request
->
file
(
'image'
);
// 返回完整图片地址
$imageUrl
=
Storage
::
url
(
$path
);
// 生成唯一文件名
$fileName
=
time
()
.
'.'
.
$image
->
getClientOriginalExtension
();
// 保存图片到指定路径
$tempPath
=
$image
->
storeAs
(
'app/public'
,
$fileName
);
// 读取文件内容
$fileContent
=
file_get_contents
(
storage_path
(
'app/public/'
.
$fileName
));
// 上传到腾讯云
Storage
::
disk
(
'cos'
)
->
put
(
'doctor-images/'
.
$fileName
,
$fileContent
);
// 返回图片地址
$imageUrl
=
Storage
::
disk
(
'cos'
)
->
url
(
'doctor-images/'
.
$fileName
);
// 签名图片地址记录到数据库
// 签名图片地址记录到数据库
$authInfo
=
auth
(
'api'
)
->
user
();
$authInfo
=
auth
(
'api'
)
->
user
();
$doctor
=
DoctorModel
::
where
(
'user_id'
,
$authInfo
->
id
)
->
first
();
$doctor
=
DoctorModel
::
where
(
'user_id'
,
$authInfo
->
id
)
->
first
();
$doctor
->
signed_pic
=
$imageUrl
;
$doctor
->
signed_pic
=
$imageUrl
;
if
(
$doctor
->
save
())
{
if
(
$doctor
->
save
())
{
// 删除临时文件
unlink
(
storage_path
(
'app/public/'
.
$fileName
));
return
$this
->
success
([
'message'
=>
'ok'
,
'url'
=>
$imageUrl
]);
return
$this
->
success
([
'message'
=>
'ok'
,
'url'
=>
$imageUrl
]);
}
}
...
...
app/Api/Controllers/PharmacistController.php
View file @
4e8109d8
...
@@ -180,33 +180,15 @@ public function upload(Request $request)
...
@@ -180,33 +180,15 @@ public function upload(Request $request)
// 获取上传的图片
// 获取上传的图片
if
(
$request
->
hasFile
(
'image'
))
{
if
(
$request
->
hasFile
(
'image'
))
{
// 获取图片文件
$path
=
Storage
::
putFile
(
'license-images'
,
$request
->
file
(
'image'
));
$image
=
$request
->
file
(
'image'
);
// 返回完整图片地址
$imageUrl
=
Storage
::
url
(
$path
);
// 生成唯一文件名
$fileName
=
time
()
.
'.'
.
$image
->
getClientOriginalExtension
();
// 保存图片到指定路径
$tempPath
=
$image
->
storeAs
(
'app/public'
,
$fileName
);
// 读取文件内容
$fileContent
=
file_get_contents
(
storage_path
(
'app/public/'
.
$fileName
));
// 上传到腾讯云
Storage
::
disk
(
'cos'
)
->
put
(
'pharmacist-images/'
.
$fileName
,
$fileContent
);
// 返回图片地址
$imageUrl
=
Storage
::
disk
(
'cos'
)
->
url
(
'pharmacist-images/'
.
$fileName
);
// 签名图片地址记录到数据库
// 签名图片地址记录到数据库
$pharmacist
->
signed_pic
=
$imageUrl
;
$pharmacist
->
signed_pic
=
$imageUrl
;
if
(
$pharmacist
->
save
())
{
if
(
$pharmacist
->
save
())
{
// 删除临时文件
unlink
(
storage_path
(
'app/public/'
.
$fileName
));
return
$this
->
success
([
'message'
=>
'ok'
,
'url'
=>
$imageUrl
]);
return
$this
->
success
([
'message'
=>
'ok'
,
'url'
=>
$imageUrl
]);
}
}
return
$this
->
failed
(
'签名图片上传失败'
);
return
$this
->
failed
(
'签名图片上传失败'
);
}
else
{
}
else
{
return
$this
->
failed
(
'签名图片上传失败'
);
return
$this
->
failed
(
'签名图片上传失败'
);
...
...
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