Files
heping-api/app/controller/Upload.php
2022-09-08 16:43:38 +08:00

34 lines
970 B
PHP
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?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('服务器繁忙,请联系管理员');
}
}
}