<?php
namespace app\admin\controller;
use think\Controller;
use app\admin\logic\UserLogic;
class Base extends Controller
{
public function initialize()
{
$user = new UserLogic();
$res = $user->check_login_status();
if (!$res) {
$this->error("请登录", 'admin/login/index', ['tophref' => 1]);
}
}
public function uploadfile(){
$type = input("type","image");
$path = "./uploads/".$type;
$file = request()->file('image');
$info = $file->move($path);
if($info){
return json($path."/".$info->getSaveName());
}else{
return json(msg_error($file->getError()));
}
}
public function del_image()
{
if (request()->isAjax()) {
$url = input("param.url", '');
if (empty($url)) {
return json(msg_error("参数不存在!"));
}
try {
$res = unlink($url);
if ($res === true) {
return json(msg_success("删除成功!"));
}else{
return json(msg_error("删除失败!"));
}
} catch (\Exception $e) {
return json(msg_error($e->getMessage()));
}
}
}
}
?>