分享一个不到3KB的阿里图床源码

教程 7个月前 MJJ导航
601 0

源码地址:https://github.com/iAJue/Alibaba_pic

二开修改版,简化:

源码 index.html

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<title>阿里图床</title>
<link rel="stylesheet" class="external" rel="nofollow" target="_blank" href="https://www.mjjloc.com/go/?url=aHR0cHM6Ly93d3cubGF5dWljZG4uY29tL2xheXVpLXYyLjUuNi9jc3MvbGF5dWkuY3Nz">
<style type="text/css">
body { margin: auto; max-width: 720px; word-wrap:break-word; }
</style>
</head>
<body>

<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
<legend>拖拽上传</legend>
</fieldset>

<div class="layui-upload-drag" id="upload">
<i class="layui-icon"></i>
<p>点击上传,或将文件拖拽到此处</p>
</div>

<div class="layui-hide" id="uploadDemoView">
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 30px;">
<legend>文件信息</legend>
</fieldset>
<img src="" alt="上传成功后渲染" style="max-width: 300px"><hr>
<span id="url"></span>
</div>

<script src="https://www.layuicdn.com/layui-v2.5.6/layui.js"></script>
<script>
layui.use(['layer', 'form', 'upload'], function(){
var layer = layui.layer
,$ = layui.jquery
,form = layui.form
,upload = layui.upload;

upload.render({
elem: '#upload'
,url: 'upload.php' //改成您自己的上传接口
,done: function(res){
layer.msg('上传成功');
layui.$('#uploadDemoView').removeClass('layui-hide').find('img').attr('src',res.url);
layui.$('#url').html(res.url);
console.log(res)
}
});
});
</script>
</body>
</html>

upload.php

<?php

$file = $_FILES['file'];
if (is_uploaded_file($file['tmp_name']))
{
$extension = pathinfo($file['name'])['extension'];
$imgname = time().rand(100,1000).'.'.$extension;
if (move_uploaded_file($file['tmp_name'], $imgname))
{
$data = array
(
'scene' => 'aeMessageCenterV2ImageRule',
'name' =>$imgname,
'file' => new \CURLFile(realpath($imgname))
);
$res = json_decode(icurl('https://kfupload.alibaba.com/mupload',$data));
@unlink($imgname);
if ($res->msg == 0)
{
echo json_encode($res);
}
}
}

function icurl($url, $data){
$ch = curl_init();
curl_setopt($ch,CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
$res = curl_exec($ch);
curl_close($ch);
return $res;
}
版权声明:MJJ导航 发表于 2020-04-09 18:37:20。
转载请注明:分享一个不到3KB的阿里图床源码 | MJJ导航 - mjjloc.com

暂无评论

暂无评论...