fix bugs upload ảnh nhân viên

This commit is contained in:
dongpd 2020-11-13 10:10:15 +07:00
parent b030073be7
commit f489ecb7cf
4 changed files with 11 additions and 5 deletions

View File

@ -3,7 +3,8 @@
return [ return [
"hideInfomation" => false, "hideInfomation" => false,
"TCTECH" => true, "TCTECH" => true,
"CardService" => "192.168.10.200:2001", "CardService" => "192.168.1.166:2001",
"dataPath" => "AC/",
"time" => 1606755599, "time" => 1606755599,
"pageSize" => 200 "pageSize" => 200
]; ];

View File

@ -325,7 +325,11 @@ class StaffController extends Controller {
public function actionImage() { public function actionImage() {
if (Yii::$app->request->post()) { if (Yii::$app->request->post()) {
$model = new common(); $model = new common();
return $model->UploadFile("AnhNhanVien", ["PNG", "JPG", "JPEG", "GIF"], "staff"); Yii::$app->response->format = "json";
return [
"dataPath" => Yii::$app->params["dataPath"],
"url" => $model->UploadFile("AnhNhanVien", ["PNG", "JPG", "JPEG", "GIF"], "staff")
];
} }
} }

View File

@ -67,7 +67,7 @@
<legend>Hình nhân viên</legend> <legend>Hình nhân viên</legend>
{$img=$directoryAsset|cat:"/img/user2-160x160.jpg"} {$img=$directoryAsset|cat:"/img/user2-160x160.jpg"}
{if $model->image} {if $model->image}
{$img="/"|cat:$model->image} {$img="/"|cat:Yii::$app->params['dataPath']|cat:trim($model->image)}
{/if} {/if}
<img src="{$img}" id='staff-img' width="100%" class="img-thumbnail" style="cursor: pointer;"> <img src="{$img}" id='staff-img' width="100%" class="img-thumbnail" style="cursor: pointer;">
<div class="hidden"> <div class="hidden">

View File

@ -251,8 +251,9 @@ function btnImage() {
classes: 'btn btn-default', classes: 'btn btn-default',
fakeInputContent: '<span class=\'fa fa-file-image-o\'></span> Chọn hình ảnh', fakeInputContent: '<span class=\'fa fa-file-image-o\'></span> Chọn hình ảnh',
onUploaded: function (data) { onUploaded: function (data) {
$("#staff-img").attr("src", "/" + data); var res = JSON.parse(data);
$("input[name='AnhNhanVienUrl']").val(data); $("#staff-img").attr("src", "/" + res.dataPath + res.url);
$("input[name='AnhNhanVienUrl']").val(res.url);
common.uploadBlock(false); common.uploadBlock(false);
} }
}).addInstance('AnhNhanVien'); }).addInstance('AnhNhanVien');