<?php
/**
 *  Guojiz网址导航系统
 *	www.guojiz.com
 *  作者：梦雨
 *  @ QQ50361804
 */
namespace app\admin\controller;
use think\Controller;
class Upload extends Common
{
	
    function _initialize()
    {
        parent::_initialize();
        $this->model = model('admin/up');
    }
    public function upimage()
    {
        $rs=checkHex($_FILES['file']['tmp_name']);
        if ($rs==5) {
            return array('code' => 0, 'msg' => '当前文件有问题不能上传');
        } 
        if (!session('userid') || !session('username')) {
            $this->error('亲！请登录',url('bbs/login/index'));
        } else {
        return json($this->model->upfile('images'));
        }
    }
    public function upfile()
    {
        $rs=checkHex($_FILES['file']['tmp_name']);
        if ($rs==5) {
            return array('code' => 0, 'msg' => '当前文件有问题不能上传');
        } 
        if (!session('userid') || !session('username')) {
            $this->error('亲！请登录',url('bbs/login/index'));
        } else {
        return json($this->model->upfile('files'));
        }
    }
    
    public function Pic()
    {
        $rs=checkHex($_FILES['file']['tmp_name']);
        if ($rs==5) {
            return array('code' => 0, 'msg' => '当前文件有问题不能上传');
        } 
        if (!session('userid') || !session('username')) {
            $this->error('亲！请登录',url('bbs/login/index'));
        } else {
			$file = request()->file('FileName');
			$info = $file->validate(['size'=>5242880,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . DS . 'uploads');
			if ($info) {
				$path = WEB_URL . DS . 'uploads' . DS . $info->getSaveName();
				echo str_replace("\\", "/", $path);
              }
		}
    }
 
}