imgurl/functions/cvupload.php

98 lines
2.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
//载入配置文件
include_once("./class/class.user.php");
//检查用户是否登录
$status = $basis->check($config);
//检查用户是否登陆来判断上传目录
if($status == 'islogin') {
//设置上传路径
$updir = $config['admindir'];
}
else{
$updir = $config['userdir'];
//限制用户上传数量
$basis->limitnum();
}
//获取上传者信息
$ip = $basis->getip();
$ua = $_SERVER['HTTP_USER_AGENT'];
$date = date('Y-m-d',time());
//根据IP、ua、时间生成一个唯一的md5值
$picname = md5($ip.$ua.date('Y-m-d H:i:s',time()));
//截取16个字符
$picname = substr($picname,8,16).'.png';
//本月图片路径
$monthdir = APP.$updir.'/'.date('ym',time());
$onepath = $updir.'/'.date('ym',time()).'/'.$picname;
//路径不存在,则创建路径
if(!file_exists($monthdir)){
mkdir($monthdir,0777);
}
//图片完整存储路径
$picpath = APP.$onepath;
//echo $picpath;
//替换一下以免windows出现问题
$picpath = str_replace("\\","/",$picpath);
//echo $picpath;
//接接收ase64图片
$picfile = $_POST['content'];
$picfile = base64_decode($picfile);
//echo $picfile;
//存储图片
file_put_contents($picpath, $picfile);
//获取文件mime类型
//如果不是图片文件,终止执行
if(!$basis->mime($picpath)){
unlink($picpath);
$arr = array(
"code" => 0,
"msg" => '不允许的文件类型'
);
$json = json_encode($arr);
echo $json;
exit;
}
//继续执行并写入数据库
$last_user_id = $database->insert("imginfo", [
"path" => $onepath,
"ip" => $ip,
"ua" => $ua,
"date" => $date,
"dir" => $updir,
"compress" => 0,
"level" => 0
]);
//var_dump($database->log());
//返回最后的ID
$account_id = $database->id();
//写入数据库成功返回json数据
if($last_user_id){
$url = $config['domain'].$onepath;
rejson(1,$url,$account_id);
}
//echo $picpath;
//var_dump($picfile);
?>
<?php
//返回json数据
function rejson($code,$url,$id = 0){
$arr = array(
"code" => $code,
"url" => $url,
"id" => $id
);
$json = json_encode($arr);
echo $json;
}
?>