update biface local
This commit is contained in:
@@ -5,6 +5,8 @@ namespace app\controllers;
|
||||
use Yii;
|
||||
use yii\web\Controller;
|
||||
use yii\filters\VerbFilter;
|
||||
use yii\helpers\FileHelper;
|
||||
use app\models\CaptureLogs;
|
||||
|
||||
/**
|
||||
* CardController implements the CRUD actions for Card model.
|
||||
@@ -51,4 +53,37 @@ class ApiController extends Controller {
|
||||
}
|
||||
}
|
||||
|
||||
public function actionGetLogs() {
|
||||
if (Yii::$app->request->post()) {
|
||||
$post = Yii::$app->request->bodyParams;
|
||||
$time = date_format(date_create_from_format('Y-m-d H:i:s', $post['time']), 'U');
|
||||
$key = $this->generateRandomString();
|
||||
$RootFolder = Yii::getAlias('@webroot') . "/data/uploads";
|
||||
$targetPath = $RootFolder . "/face";
|
||||
$fileName = "face_" . $key . "_" . $time . ".png";
|
||||
FileHelper::createDirectory($targetPath, 0777);
|
||||
file_put_contents($targetPath . "/" . $fileName, base64_decode($post['image']));
|
||||
|
||||
if ($post["id"] == 0) {
|
||||
$model = new CaptureLogs();
|
||||
$model->create([
|
||||
"Time" => $time,
|
||||
"Image" => $fileName
|
||||
]);
|
||||
}
|
||||
Yii::$app->response->format = "json";
|
||||
return ["status" => "success"];
|
||||
}
|
||||
}
|
||||
|
||||
public function generateRandomString($length = 10) {
|
||||
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
||||
$charactersLength = strlen($characters);
|
||||
$randomString = '';
|
||||
for ($i = 0; $i < $length; $i++) {
|
||||
$randomString .= $characters[rand(0, $charactersLength - 1)];
|
||||
}
|
||||
return $randomString;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user