34 lines
970 B
PHP
34 lines
970 B
PHP
<?php
|
||
namespace app\controller;
|
||
|
||
use think\facade\Db;
|
||
|
||
class Upload
|
||
{
|
||
public function image()
|
||
{
|
||
if(empty($GLOBALS['data']['userid'])){
|
||
return show("请上传TOKEN!");
|
||
}
|
||
if(empty($GLOBALS['data']['file'])){
|
||
return show("请选择图片!");
|
||
}
|
||
$file = $GLOBALS['data']['file'];
|
||
$dir = env('UPLOAD_DIRECTORY');
|
||
if(!is_dir($dir)){
|
||
mkdir($dir, 0777, true);
|
||
}
|
||
$ext = getExt($file['name']);
|
||
$newfilename = uniqid().rand(10000,99999).'.'.$ext;
|
||
if(move_uploaded_file($file['tmp_name'], $dir.'/'.$newfilename)){
|
||
$but = aliyun($newfilename);
|
||
if(empty($but["url"])){
|
||
return show('服务器繁忙,请联系管理员');
|
||
}
|
||
return show('上传成功',SUCCESS_CODE,['url'=>$but['url']]);
|
||
}else{
|
||
return show('服务器繁忙,请联系管理员');
|
||
}
|
||
|
||
}
|
||
} |