Skip to content

Commit

Permalink
V1.0版本发布
Browse files Browse the repository at this point in the history
  • Loading branch information
szvone committed Oct 1, 2018
1 parent edc40c8 commit b86415a
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 9 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@

超简Api图床 V0.1 —— 专为Api而生
超简Api图床 V1.0 —— 专为Api而生
===============


超简Api图床 V0.1 基于ThinPhP 5.1实现的一套Api图床程序,主要包含以下功能
超简Api图床 V1.0 基于ThinPhP 5.1实现的一套Api图床程序,主要包含以下特色

+ 无数据库模式,简单配置,一键搭建
+ 第三方接口接入,不占用服务器空间
+ 接入搜狗Api平台,无需配置,全球CDN加速,永久不限量图片存储
+ 接入新浪Api平台,无需配置,全球CDN加速,永久不限量图片存储
+ 支持服务器存储模式,代替普通图床
+ 超简单Api使用,提供统一Api实现图片上传
+ 通讯密钥过滤恶意上传
+ 支持跨域提交访问
+ 免费、开源

Expand All @@ -30,6 +32,12 @@
+ 根据主页显示的Api接口,调用Api接口,将会返回对应的图片地址
+ 使用主页提供的测试工具,手动选择图片上传,会显示对应的图片地址

## 注意

+ 如果图床模式为服务器存储,请务必参考下面的资料将public/uploads目录设定为无权限执行PHP程序目录,保证服务器的安全性
+ https://blog.csdn.net/alen_xiaoxin/article/details/60783141
+ https://www.jb51.net/article/94061.htm

## 版权信息

超简Api图床遵循 MIT License 开源协议发布,并提供免费使用。
Expand Down
39 changes: 33 additions & 6 deletions application/index/controller/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,10 @@ public function upImg(){
//使用新浪图床
$res = SinaApi::Upload();
return json($res);
}else if ($type == 3){
//使用新浪图床
$res = $this->upload();
return json($res);
}else{
return json(array("code"=>"-1","msg"=>"类型错误","img"=>null));
}
Expand Down Expand Up @@ -104,14 +108,37 @@ public function upload(){


// 获取表单上传文件 例如上传了001.jpg
$file = request()->file('file');
$info = $file->validate(['size'=>2555678,'ext'=>'jpg,png,gif'])->move(ROOT_PATH . 'public' . DS . 'uploads');
// 移动到框架应用根目录/public/uploads/ 目录下
if($file){
return json(array("code"=>"1","msg"=>"上传成功","img"=>$info->getSaveName()));
$new_file = "/uploads/".date('Ymd',time())."/";


if(!file_exists(ROOT_PATH.$new_file)){
mkdir(ROOT_PATH.$new_file, 0777,true);
}

$hz = substr(input("imgBase64"),0,2);

$http_type = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == 'on') || (isset($_SERVER['HTTP_X_FORWARDED_PROTO']) && $_SERVER['HTTP_X_FORWARDED_PROTO'] == 'https')) ? 'https://' : 'http://';
$imgurl = $http_type . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI'];


if ($hz == "iV"){
$type = "png";
}else if($hz == "/9"){
$type = "jpg";
}else{
return array("code"=>"-1","msg"=>"图片格式错误","img"=>null);
}



$new_file = $new_file.time().".{$type}";
if (file_put_contents(ROOT_PATH.$new_file, base64_decode(input("imgBase64")))){

return array("code"=>"1","msg"=>"上传成功","img"=>str_replace("/api",$new_file,$imgurl));
}else{
return json(array("code"=>"-1","msg"=>"类型错误:"+getError(),"img"=>null));
return array("code"=>"-1","msg"=>"上传失败","img"=>null);
}

}

}
3 changes: 2 additions & 1 deletion public/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
RewriteRule ^(.*)$ index.php?s=$1 [QSA,PT,L]
RewriteRule uploads/(.*).(php)$ [F]
</IfModule>
4 changes: 4 additions & 0 deletions public/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,9 @@

// 支持事先使用静态方法设置Request对象和Config对象

// 定义应用目录
define('ROOT_PATH', str_replace("\\","/",__DIR__ ));

// 执行应用并响应
Container::get('app')->run()->send();

0 comments on commit b86415a

Please sign in to comment.