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) {
$model = new CaptureLogs();
$model->create([
"Staff" => 0,
"Time" => $time,
"Image" => $fileName
]);

View File

@ -170,7 +170,7 @@ class ConfigController extends Controller {
]
];
$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']) {
$t = json_decode($tempConfig['data'], true);
$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".
*
* @property int $id
* @property int $staff_id
* @property int $time
* @property string $image
* @property int $status
@ -27,7 +28,7 @@ class CaptureLogs extends \yii\db\ActiveRecord {
*/
public function rules() {
return [
[['time', 'status'], 'integer'],
[['staff_id', 'time', 'status'], 'integer'],
[['image', 'remark'], 'string'],
];
}
@ -47,6 +48,7 @@ class CaptureLogs extends \yii\db\ActiveRecord {
public function create($data) {
$r = $this->load([
'staff_id' => $data['Staff'],
'time' => $data['Time'],
'image' => $data["Image"],
'status' => 0,

View File

@ -172,7 +172,7 @@ class common extends \yii\db\ActiveRecord {
}
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' => [
'header' => "Content-Type: application/json",
'method' => "POST",

View File

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

View File

@ -136,6 +136,12 @@
</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 style="width: 300px;position: absolute;" id="menu" class="hidden">
@ -160,6 +166,11 @@
<div class="row">
<div class="col-md-4 text-center">
<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 class="col-md-8">
<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");
}
});
btnImage();
});
function _search(e) {
@ -181,4 +182,34 @@ 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');
}