仅仅不到3KB的阿里图床源码

原贴:https://www.hostloc.com/thread-671624-1-1.html

源码来自帖子:https://www.hostloc.com/thread-650301-1-1.html

        他那个前端好看是好看,复制有点问题,一点就打开了上传窗口,所以随便改了一下,大小不到3KB

        演示地址:http://400008.xyz/ali

直接上源码,下边两个文件保存到任意目录即可;

index.html
CSS那行被LOC吞了,https://www.layuicdn.com/layui-v2.5.6/css/layui.css

<!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" >
  <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;
}

版权声明:
作者:daung
链接:https://www.duangvps.com/archives/823
来源:Duang's Blog
文章版权归作者所有,未经允许请勿转载。

THE END
分享
二维码
海报
仅仅不到3KB的阿里图床源码
原贴:https://www.hostloc.com/thread-671624-1-1.html 源码来自帖子:https://www.hostloc.com/thread-650301-1-1.html        ……
<<上一篇
下一篇>>