upload image

This commit is contained in:
dongpd 2020-12-04 11:07:12 +07:00
parent 4187fc7239
commit df39cdf602
10 changed files with 60 additions and 4 deletions

View File

@ -68,6 +68,7 @@ class ApiController extends Controller {
if ($post["id"] == 0) { if ($post["id"] == 0) {
$model = new CaptureLogs(); $model = new CaptureLogs();
$model->create([ $model->create([
"Staff" => 0,
"Time" => $time, "Time" => $time,
"Image" => $fileName "Image" => $fileName
]); ]);

View File

@ -170,7 +170,7 @@ class ConfigController extends Controller {
] ]
]; ];
$ip = "192.168.0.42"; $ip = "192.168.0.42";
$tempConfig = json_decode(file_get_contents("http://192.168.1.241:4004/ReadAPIConfig", false, stream_context_create($options)), true); $tempConfig = json_decode(file_get_contents("http://localhost:4004/ReadAPIConfig", false, stream_context_create($options)), true);
if ($tempConfig['status']) { if ($tempConfig['status']) {
$t = json_decode($tempConfig['data'], true); $t = json_decode($tempConfig['data'], true);
$temp = explode("/", $t['url']); $temp = explode("/", $t['url']);

View File

@ -172,4 +172,15 @@ class ListManagementController extends Controller {
} }
} }
public function actionUpload() {
if (Yii::$app->request->post()) {
$model = new common();
Yii::$app->response->format = "json";
return [
"dataPath" => "BiFace/",
"url" => $model->UploadFile("AnhNhanVien", ["PNG", "JPG", "JPEG", "GIF"], "temp")
];
}
}
} }

BIN
db/app.db

Binary file not shown.

View File

@ -8,6 +8,7 @@ use Yii;
* This is the model class for table "capture_logs". * This is the model class for table "capture_logs".
* *
* @property int $id * @property int $id
* @property int $staff_id
* @property int $time * @property int $time
* @property string $image * @property string $image
* @property int $status * @property int $status
@ -27,7 +28,7 @@ class CaptureLogs extends \yii\db\ActiveRecord {
*/ */
public function rules() { public function rules() {
return [ return [
[['time', 'status'], 'integer'], [['staff_id', 'time', 'status'], 'integer'],
[['image', 'remark'], 'string'], [['image', 'remark'], 'string'],
]; ];
} }
@ -47,6 +48,7 @@ class CaptureLogs extends \yii\db\ActiveRecord {
public function create($data) { public function create($data) {
$r = $this->load([ $r = $this->load([
'staff_id' => $data['Staff'],
'time' => $data['Time'], 'time' => $data['Time'],
'image' => $data["Image"], 'image' => $data["Image"],
'status' => 0, 'status' => 0,

View File

@ -172,7 +172,7 @@ class common extends \yii\db\ActiveRecord {
} }
public static function requestToEngine($path, $data) { public static function requestToEngine($path, $data) {
return file_get_contents("http://192.168.2.158:2305" . $path, false, stream_context_create([ return file_get_contents("http://localhost:2305" . $path, false, stream_context_create([
'http' => [ 'http' => [
'header' => "Content-Type: application/json", 'header' => "Content-Type: application/json",
'method' => "POST", 'method' => "POST",

View File

@ -1,7 +1,7 @@
copy.src.files=false copy.src.files=false
copy.src.on.open=false copy.src.on.open=false
copy.src.target= copy.src.target=
remote.connection=missing-config remote.connection=BiFace-99bab6
remote.directory=/BiFace_Server_Lite remote.directory=/BiFace_Server_Lite
remote.upload=ON_SAVE remote.upload=ON_SAVE
run.as=LOCAL run.as=LOCAL

View File

@ -136,6 +136,12 @@
</div> </div>
</div> </div>
</div> </div>
<hr style="border-top: 1px solid #000;">
<div class="text-center">
<button class="btn btn-info" onclick="_form();">
<i class="fa fa-plus-circle"></i> Thêm mới
</button>
</div>
</div> </div>
</div> </div>
<div style="width: 300px;position: absolute;" id="menu" class="hidden"> <div style="width: 300px;position: absolute;" id="menu" class="hidden">
@ -160,6 +166,11 @@
<div class="row"> <div class="row">
<div class="col-md-4 text-center"> <div class="col-md-4 text-center">
<img src="" class="img-thumbnail" id="FaceImage" style="width: 150px;height: 150px;"> <img src="" class="img-thumbnail" id="FaceImage" style="width: 150px;height: 150px;">
<div class="">
<input type="file" name="AnhNhanVien" id="AnhNhanVien">
<input type="hidden" name="AnhNhanVienUrl" value="">
<input type="hidden" name="url_upload_staff_image" value="{Url::to(['upload'])}">
</div>
</div> </div>
<div class="col-md-8"> <div class="col-md-8">
<div class="row"> <div class="row">

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.0 KiB

View File

@ -14,6 +14,7 @@ $(function () {
$("#delete-btn-group").addClass("hidden"); $("#delete-btn-group").addClass("hidden");
} }
}); });
btnImage();
}); });
function _search(e) { function _search(e) {
@ -182,3 +183,33 @@ function batchDelete(e) {
}); });
} }
} }
function _form() {
$("#form").removeClass("hidden");
$("#FaceImage").attr("src", "/BiFace/images/user2-160x160.jpg");
}
function btnImage() {
var fData = {
UploadImage: true
};
fData[common.csrfParam] = common.csrf;
new afuButton({
uploadURI: $("input[name='url_upload_staff_image']").val(),
formData: fData,
wrap: {
tagName: 'div',
classes: ''
},
fileExtension: '.png,.jpg,.jpeg,.gif',
fileSizeLimit: 1,
classes: 'btn btn-default btn-xs',
fakeInputContent: '<span class=\'fa fa-file-image-o\'></span> Chọn hình ảnh',
onUploaded: function (data) {
var res = JSON.parse(data);
$("#FaceImage").attr("src", "/" + res.dataPath + res.url);
$("input[name='AnhNhanVienUrl']").val(res.url);
common.uploadBlock(false);
}
}).addInstance('AnhNhanVien');
}