由于蓝奏云增加了登录验证,已经不能使用账号密码的方式登录了,请自行抓取 cookie 进行使用(cookie 有效期大概是 20 天左右)。效果图:HTML代码:<!doctype html>
<html lang="zh">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<link rel="stylesheet" href="//ku.oioweb.cn/LayUI/layui/css/layui.css">
<script src="//ku.oioweb.cn/jQuery/3.4.1/jquery.min.js"></script>
<script src="//ku.oioweb.cn/LayUI/layui/layui.all.js"></script>
<script src="//ku.oioweb.cn/clipboard.js/2.0.4/clipboard.min.js"></script>
</head>
<body>
<div class="layui-upload-drag" id="testList" style="width: 100%;padding: 51px 0;border: none;">
<i class="layui-icon"></i>
<p>点击上传,或将文件拖拽到此处</p>
</div>
<div class="layui-upload">
<div class="layui-upload-list" style="text-align: center;">
<table class="layui-table">
<thead>
<tr>
<th>文件名</th>
<th>大小</th>
<th>状态</th>
<th>操作</th>
</tr>
</thead>
<tbody id="demoList"></tbody>
</table>
</div>
<button type="button" class="layui-btn layui-btn-fluid layui-btn-radius" id="testListAction">开始上传</button>
</div>
<script>
;!function () {
var upload = layui.upload;
var demoListView = $('#demoList')
, uploadListIns = upload.render({
elem: '#testList'
,
url: 'api.php'
,
accept: 'file'
,
data: {type: "upload"}
,
size: 1024 * 1024 * 100
,
exts: 'doc|docx|zip|rar|apk|ipa|txt|exe|7z|e|z|ct|ke|cetrainer|db|tar|pdf|w3x|epub|mobi|azw|azw3|osk|osz|xpa|cpk|lua|jar|dmg|ppt|pptx|xls|xlsx|mp3|ipa|iso|img|gho|ttf|ttc|txf|dwg|bat|dll'
,
multiple: true
,
auto: false
,
bindAction: '#testListAction'
,
choose: function (obj) {
var files = this.files = obj.pushFile(); //将每次选择的文件追加到文件队列
//读取本地文件
obj.preview(function (index, file, result) {
var tr = $(['<tr id="upload-' + index + '">'
, '<td>' + file.name + '</td>'
, '<td>' + (file.size / 1024).toFixed(1) + 'kb</td>'
, '<td>等待上传</td>'
, '<td>'
, '<button class="layui-btn layui-btn-xs demo-reload layui-hide">重传</button>'
, '<button class="layui-btn layui-btn-xs layui-btn-danger demo-delete">删除</button>'
, '</td>'
, '</tr>'].join(''));
//单个重传
tr.find('.demo-reload').on('click', function () {
obj.upload(index, file);
});
//删除
tr.find('.demo-delete').on('click', function () {
delete files[index];
tr.remove();
uploadListIns.config.elem.next()[0].value = '';
});
demoListView.append(tr);
});
}
,
done: function (res, index, upload) {
if (res.code == 1) { //上传成功
var tr = demoListView.find('tr#upload-' + index)
, tds = tr.children();
tds.eq(2).html('<span style="color: #5FB878;">上传成功</span>');
tds.eq(3).html('<button type="button" class="layui-btn layui-btn-sm copy" data-clipboard-text="' + res.url + '"><i class="layui-icon"></i></button><button class="layui-btn layui-btn-sm delfile" fileid="' + res.id + '"><i class="layui-icon"></i></button>');
tr.find('.delfile').on('click', function () {
$.post({
url: "api.php",
beforeSend: function () {
layer.load();
},
data: {id: $(this).attr('fileid'), type: "del_file"},
success: function (data) {
if (data.code == 1) {
layer.msg("删除成功!");
tr.remove();
} else {
layer.msg("删除失败!");
}
layer.closeAll('loading');
},
error: function (data) {
layer.closeAll('loading');
layer.msg("删除失败!");
}
})
});
var clipboard = new ClipboardJS('.copy');
clipboard.on('success', function (e) {
layer.msg("复制成功!");
e.clearSelection();
});
clipboard.on('error', function (e) {
layer.msg("复制失败!");
});
return delete this.files[index];
} else {
layer.msg(res.msg);
}
this.error(index, upload);
}
,
error: function (index, upload) {
var tr = demoListView.find('tr#upload-' + index)
, tds = tr.children();
tds.eq(2).html('<span style="color: #FF5722;">上传失败</span>');
tds.eq(3).find('.demo-reload').removeClass('layui-hide'); //显示重传
}
});
}();
</script>
</body>
</html>api代码:<?php
header('Access-Control-Allow-Origin:*');
header('Content-type:application/json; charset=utf-8');
error_reporting(0);
$Lanzou = new Lanzou();
!empty($_POST['type']) ? $type = $_POST['type'] : exit($Lanzou->error("请勿直接访问!"));
switch ($type){
case "upload":
$array= array("doc", "docx", "zip", "rar", "apk", "ipa", "txt", "exe", "7z", "e", "z", "ct", "ke", "cetrainer", "db", "tar", "pdf", "w3x", "epub", "mobi", "azw", "azw3", "osk", "osz", "xpa", "cpk", "lua", "jar", "dmg", "ppt", "pptx", "xls", "xlsx", "mp3", "ipa", "iso", "img", "gho", "ttf", "ttc", "txf", "dwg", "bat", "dll");
$tmp=explode(".",$_FILES['file']['name']);
$file = $_FILES["file"]["tmp_name"];
$extension=end($tmp);
if($_FILES['file']['error']>0 || $file == ""){
exit($Lanzou->error("文件损坏!"));
}else{
if (($_FILES['file']['size']<100*1024*1024) && in_array($extension, $array)){
move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
$files = "upload/" . $_FILES["file"]["name"];
}
echo json_encode($Lanzou->upload_file($files));
unlink($files);
}
break;
case "del_file":
!empty($_POST['id']) ? $id = $_POST['id'] : exit($Lanzou->error("请传入文件ID!"));
echo json_encode($Lanzou->del_file($id));
break;
default:
$Lanzou->error("请勿直接访问!");
}
/**
* Class Lanzou
* 蓝奏云在线免登陆上传
*/
class Lanzou
{
private $config = [
'cookie' => 'phpdisk_info=VGlSYFc1Vm0CMg5XD2EGVVZqDGcJOlV3BmtTZwYyCjhXYl9sUQoDPFMwAmYLYFc%2;', //此处填写自己抓取的cookie
'upload_file' => 'https://pc.woozooo.com/fileup.php',
'del_file' => 'https://pc.woozooo.com/doupload.php',
];
public function upload_file($file)
{
$upload = [
'post' => [
'task' => 1,
'upload_file' => new CURLFile(realpath($file))
],
'cookie' => $this->config['cookie']
];
$json = json_decode($this->get_curl($this->config['upload_file'], $upload));
if ($json->zt == 1) {
return [
"code" => 1,
"msg" => $json->info,
"url" => $json->text[0]->is_newd . "/" . $json->text[0]->f_id,
"name" => $json->text[0]->name_all,
"size" => $json->text[0]->size,
"id" => $json->text[0]->id
];
} else {
return [
"code" => -1,
"msg" => $json->info
];
}
}
public function del_file($id)
{
$del = [
"post" => [
'task' => 6,
'file_id' => $id
],
'cookie' => $this->config['cookie']
];
$json = json_decode($this->get_curl($this->config['del_file'], $del));
if ($json->zt == 1) {
return [
"code" => 1,
"msg" => $json->info
];
}else{
return [
"code" => -1,
"msg" => $json->info
];
}
}
public function get_curl($url, $paras = array())
{
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
if ($paras['httpheader']) { // 请求头
$httpheader = $paras['httpheader'];
} else {
$httpheader[] = "Accept:*/*";
$httpheader[] = "Accept-Encoding:gzip,deflate,sdch";
$httpheader[] = "Accept-Language:zh-CN,zh;q=0.8";
$httpheader[] = "Connection:close";
}
curl_setopt($ch, CURLOPT_HTTPHEADER, $httpheader);
if ($paras['ctime']) { // 连接超时
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, $paras['ctime']);
}
if ($paras['rtime']) { // 读取超时
curl_setopt($ch, CURLOPT_TIMEOUT, $paras['rtime']);
}
if ($paras['post']) {
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $paras['post']);
}
if ($paras['header']) {
curl_setopt($ch, CURLOPT_HEADER, true);
}
if ($paras['cookie']) {
curl_setopt($ch, CURLOPT_COOKIE, $paras['cookie']);
}
if ($paras['refer']) {
if ($paras['refer'] == 1) {
curl_setopt($ch, CURLOPT_REFERER, 'http://m.qzone.com/infocenter?g_f=');
} else {
curl_setopt($ch, CURLOPT_REFERER, $paras['refer']);
}
}
if ($paras['ua']) {
curl_setopt($ch, CURLOPT_USERAGENT, $paras['ua']);
} else {
curl_setopt($ch, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/65.0.3325.181 Safari/537.36");
}
if ($paras['nobody']) {
curl_setopt($ch, CURLOPT_NOBODY, 1);
}
curl_setopt($ch, CURLOPT_ENCODING, "gzip");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$ret = curl_exec($ch);
curl_close($ch);
return $ret;
}
public function error($msg)
{
echo json_encode([
"code" => -1,
"msg" => $msg
], 320);
}
}PS注意项目:请在程序目录下新建文件夹(upload)用于临时存储文件 支持多文件上传 上传失败文件重新上传 直接复制链接 在线删除文件
评论
19条评论101010 Lv.1
Chrome 144.0.0.0
Windows 回复
感谢分享!
阿根廷
kinchie Lv.1
Chrome 142.0.0.0
Windows 回复
感谢楼主
,好人一生平安
北京市 歌华有线
heizhizhu Lv.1
Chrome 138.0.0.0
Windows 回复
感谢楼主
,好人一生平安
浙江省宁波市 电信
ChaoKai Lv.1 回复
局域网 对方和您在同一内部网
x495210 Lv.1 回复
四川省 移动
semtopher Lv.1 回复
感谢分享!
北京市 联通
kertyu578 Lv.1
Internet Explorer 11.0
Windows 7 回复
huifu,xiex
江苏省苏州市 电信
liuhuhu Lv.1
Chrome 119.0.0.0
Windows 回复
111
山东省潍坊市临朐县 电信
13237312 Lv.1
Chrome 119.0.0.0
Windows 回复
真不错 好人啊
广东省深圳市 电信
Kkoalaxy Lv.1
Firefox 115.0
Windows 回复
111
重庆市 联通