<?php
/*
 *	www.myucms.com
 *  作者：梦雨
 *  @ QQ50361804
*/
namespace app\admin\controller;
use Think\Loader;
use think\Model;
use think\Db;
use think\File;
use think\Request;
use org\Http;
use org\Upload;
use think\Controller;
class upimg extends Controller
{
	 function _initialize()
    {
        parent::_initialize();
        
    }
    public function Pic()
    {
        if (!session('userid') || !session('username')) {
            $this->error('亲！请登录',url('bbs/login/index'));
        } else {
        	if (config('web.qiniuopen') == 1) {
        		//开启七牛
            $driverConfig = array('secrectKey' => config('web.secrectKey'), 'accessKey' => config('web.accessKey'), 'domain' => config('web.domain'), 'bucket' => config('web.bucket'));
            $setting['exts'] = explode(',','jpg,png,gif');
            $setting['maxSize'] = 50 * 1024 * 1024;
            $Upload = new upload($setting, 'Qiniu', $driverConfig);
            $info = $Upload->uploadOne($_FILES['FileName']);
            if ($info) {
              echo $info['url'];
            }
        	} 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);
              }
              
        	}
		}
    }

}