forked from kevinowino869/mitrobill
Upload Admin face with Face Detection
This commit is contained in:
@ -474,6 +474,23 @@ switch ($action) {
|
||||
}
|
||||
}
|
||||
if ($d) {
|
||||
if(isset($routes['3']) && $routes['3'] == 'deletePhoto'){
|
||||
if($d['photo'] != '' && $d['photo'] != '/admin.default.png'){
|
||||
if(file_exists($UPLOAD_PATH.$d['photo'])){
|
||||
unlink($UPLOAD_PATH.$d['photo']);
|
||||
if(file_exists($UPLOAD_PATH.$d['photo'].'.thumb.jpg')){
|
||||
unlink($UPLOAD_PATH.$d['photo'].'.thumb.jpg');
|
||||
}
|
||||
}
|
||||
$d->photo = '/admin.default.png';
|
||||
$d->save();
|
||||
$ui->assign('notify_t', 's');
|
||||
$ui->assign('notify', 'You have successfully deleted the photo');
|
||||
}else{
|
||||
$ui->assign('notify_t', 'e');
|
||||
$ui->assign('notify', 'No photo found to delete');
|
||||
}
|
||||
}
|
||||
$ui->assign('id', $id);
|
||||
$ui->assign('d', $d);
|
||||
run_hook('view_edit_admin'); #HOOK
|
||||
@ -636,6 +653,55 @@ switch ($action) {
|
||||
}
|
||||
run_hook('edit_admin'); #HOOK
|
||||
if ($msg == '') {
|
||||
if (!empty($_FILES['photo']['name'])) {
|
||||
if (function_exists('imagecreatetruecolor')) {
|
||||
$hash = md5_file($_FILES['photo']['tmp_name']);
|
||||
$subfolder = substr($hash, 0, 2);
|
||||
$folder = $UPLOAD_PATH . DIRECTORY_SEPARATOR . 'photos'. DIRECTORY_SEPARATOR;
|
||||
if(!file_exists($folder)){
|
||||
mkdir($folder);
|
||||
}
|
||||
$folder = $UPLOAD_PATH . DIRECTORY_SEPARATOR . 'photos'. DIRECTORY_SEPARATOR. $subfolder. DIRECTORY_SEPARATOR;
|
||||
if(!file_exists($folder)){
|
||||
mkdir($folder);
|
||||
}
|
||||
$imgPath = $folder . $hash . '.jpg';
|
||||
if (!file_exists($imgPath)){
|
||||
File::resizeCropImage($_FILES['photo']['tmp_name'], $imgPath, 1600, 1600, 100);
|
||||
}
|
||||
if (!file_exists($imgPath.'.thumb.jpg')){
|
||||
if(_post('faceDetect') == 'yes'){
|
||||
try{
|
||||
$detector = new svay\FaceDetector();
|
||||
$detector->setTimeout(5000);
|
||||
$detector->faceDetect($imgPath);
|
||||
$detector->cropFaceToJpeg($imgPath.'.thumb.jpg', false);
|
||||
}catch (Exception $e) {
|
||||
File::makeThumb($imgPath, $imgPath.'.thumb.jpg', 200);
|
||||
} catch (Throwable $e) {
|
||||
File::makeThumb($imgPath, $imgPath.'.thumb.jpg', 200);
|
||||
}
|
||||
}else{
|
||||
File::makeThumb($imgPath, $imgPath.'.thumb.jpg', 200);
|
||||
}
|
||||
}
|
||||
if(file_exists($imgPath)){
|
||||
if($d['photo'] != ''){
|
||||
if(file_exists($UPLOAD_PATH.$d['photo'])){
|
||||
unlink($UPLOAD_PATH.$d['photo']);
|
||||
if(file_exists($UPLOAD_PATH.$d['photo'].'.thumb.jpg')){
|
||||
unlink($UPLOAD_PATH.$d['photo'].'.thumb.jpg');
|
||||
}
|
||||
}
|
||||
}
|
||||
$d->photo = '/photos/'. $subfolder. '/'. $hash. '.jpg';
|
||||
}
|
||||
if (file_exists($_FILES['photo']['tmp_name'])) unlink($_FILES['photo']['tmp_name']);
|
||||
} else {
|
||||
r2(U . 'settings/app', 'e', 'PHP GD is not installed');
|
||||
}
|
||||
}
|
||||
|
||||
$d->username = $username;
|
||||
if ($password != '') {
|
||||
$password = Password::_crypt($password);
|
||||
@ -666,7 +732,7 @@ switch ($action) {
|
||||
$d->save();
|
||||
|
||||
_log('[' . $admin['username'] . ']: $username ' . Lang::T('User Updated Successfully'), $admin['user_type'], $admin['id']);
|
||||
r2(U . 'settings/users', 's', 'User Updated Successfully');
|
||||
r2(U . 'settings/users-view/' . $id, 's', 'User Updated Successfully');
|
||||
} else {
|
||||
r2(U . 'settings/users-edit/' . $id, 'e', $msg);
|
||||
}
|
||||
|
Reference in New Issue
Block a user