更新 index.php
加入多用户管理。
This commit is contained in:
parent
d831c5c0de
commit
d948a693ba
238
index.php
238
index.php
@ -1,17 +1,20 @@
|
||||
<?php
|
||||
$base_dir='/o/';//以/即结束即可
|
||||
$user="chate.store";// 用户名
|
||||
$pwd="123456";// 密码,请记得频繁更换
|
||||
$base_dir = '/o/';//以/即结束即可
|
||||
$user = array("admin1","admin2");// 用户名,可多个
|
||||
$pwd = array("chate.store1","chate.store2");// 密码,跟用户一一对应,请记得更换
|
||||
|
||||
$authorization = false;
|
||||
if ($_SERVER['PHP_AUTH_USER'] == $user && $_SERVER['PHP_AUTH_PW'] == $pwd){
|
||||
$key = array_search($_SERVER['PHP_AUTH_USER'], $user);
|
||||
if($key !== false){
|
||||
if($_SERVER['PHP_AUTH_PW'] ==$pwd[$key]){
|
||||
$authorization = true;
|
||||
}
|
||||
}
|
||||
if(!$authorization){
|
||||
// 没登录成功,弹出要求输入用户名和密码窗口
|
||||
header("WWW-Authenticate:Basic realm='Private'");
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
exit;
|
||||
// 没登录成功,弹出要求输入用户名和密码窗口
|
||||
header("WWW-Authenticate:Basic realm='Private'");
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
exit;
|
||||
}
|
||||
|
||||
// 处理文件上传
|
||||
@ -22,8 +25,8 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
|
||||
// 检查上传错误,直接提示错误代码
|
||||
if ($error !== UPLOAD_ERR_OK) {
|
||||
echo '{"error":"上传失败,错误代码:'.$error.'"}';
|
||||
exit;
|
||||
echo '{"error":"上传失败,错误代码:'.$error.'"}';
|
||||
exit;
|
||||
}
|
||||
|
||||
// 兼容跨平台路径
|
||||
@ -71,18 +74,18 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
align-items: center;
|
||||
flex-direction: column;
|
||||
}
|
||||
.background {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-size: cover;
|
||||
z-index: -1;
|
||||
transition: opacity 1s ease-in-out;
|
||||
opacity: 1;
|
||||
}
|
||||
.container {
|
||||
.background {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-size: cover;
|
||||
z-index: -1;
|
||||
transition: opacity 1s ease-in-out;
|
||||
opacity: 1;
|
||||
}
|
||||
.container {
|
||||
width: 600px;
|
||||
overflow: hidden;
|
||||
}
|
||||
@ -161,7 +164,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
justify-content: flex-end; /* 使按钮靠右对齐 */
|
||||
margin-top: 10px; /* 添加上边距 */
|
||||
}
|
||||
|
||||
|
||||
.nav {
|
||||
display: flex;
|
||||
justify-content: center; /* 居中对齐 */
|
||||
@ -171,61 +174,66 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="background" id="background"></div>
|
||||
<div class="background" id="background"></div>
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title text-center" style="font-weight: bold;">SIW(Simple Image Web)</h4>
|
||||
<h6 class="card-title text-center" style="font-weight: bold;">简单就是美。</h6>
|
||||
<form id="uploadForm" enctype="multipart/form-data">
|
||||
<div class="mb-3">
|
||||
<label for="files" class="form-label"></label>
|
||||
<input type="file" class="form-control" id="files" name="files[]" multiple accept="image/jpeg, image/png, image/gif, image/webp, image/avif" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100" style="font-weight: bold;">开始上传</button>
|
||||
</form>
|
||||
<div id="fileList" class="file-list mt-3"></div>
|
||||
<div id="statusOutput" class="status-output"></div>
|
||||
<div class="link-output">
|
||||
<button class="btn btn-info" id="directLinkBtn">直连</button>
|
||||
<button class="btn btn-info" id="htmlCodeBtn">网页</button>
|
||||
<button class="btn btn-info" id="forumCodeBtn">论坛</button>
|
||||
<button class="btn btn-info" id="markDownCodeBtn">Markdown</button>
|
||||
<button class="btn btn-success" id="copyAllBtn">复制所有链接</button>
|
||||
<textarea id="linkText" readonly></textarea>
|
||||
</div>
|
||||
<h6 id="formatHint" class="card-title text-center">支持格式: JPEG, PNG, GIF, WEBP, AVIF 最大上传:<?php echo ini_get('upload_max_filesize');?></h6>
|
||||
<h4 class="card-title text-center" style="font-weight: bold;">SIW(Simple Image Web)</h4>
|
||||
<h6 class="card-title text-center" style="font-weight: bold;">简单就是美。</h6>
|
||||
<form id="uploadForm" enctype="multipart/form-data">
|
||||
<div class="mb-3">
|
||||
<label for="files" class="form-label"></label>
|
||||
<input type="file" class="form-control" id="files" name="files[]" multiple accept="image/jpeg, image/png, image/gif, image/webp, image/avif" required>
|
||||
</div>
|
||||
<button type="submit" class="btn btn-primary w-100" style="font-weight: bold;">开始上传</button>
|
||||
</form>
|
||||
<div id="fileList" class="file-list mt-3"></div>
|
||||
<div id="statusOutput" class="status-output"></div>
|
||||
<div class="link-output">
|
||||
<button class="btn btn-info" id="directLinkBtn">直连</button>
|
||||
<button class="btn btn-info" id="htmlCodeBtn">网页</button>
|
||||
<button class="btn btn-info" id="forumCodeBtn">论坛</button>
|
||||
<button class="btn btn-info" id="markDownCodeBtn">Markdown</button>
|
||||
<button class="btn btn-success" id="copyAllBtn">复制所有链接</button>
|
||||
<textarea id="linkText" readonly></textarea>
|
||||
</div>
|
||||
<h6 id="formatHint" class="card-title text-center">支持格式: JPEG, PNG, GIF, WEBP, AVIF 最大上传:<?php echo ini_get('upload_max_filesize');?></h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<script>
|
||||
|
||||
async function setBackgroundImages() {
|
||||
const images = ['https://cn.bing.com/th?id=OHR.SnowMoose_EN-US6949674639_1920x1080.jpg','https://cn.bing.com/th?id=OHR.IcebergsAntarctica_EN-US6829804691_1920x1080.jpg','https://cn.bing.com/th?id=OHR.KilchurnAutumn_EN-US6737063910_1920x1080.jpg','https://cn.bing.com/th?id=OHR.MtStMichel_EN-US6641012356_1920x1080.jpg','https://cn.bing.com/th?id=OHR.TomTurkeys_EN-US6212893518_1920x1080.jpg'];
|
||||
const backgroundDiv = document.getElementById('background');
|
||||
// 取必应每天的壁纸做背景
|
||||
var response = await fetch('https://raw.onmicrosoft.cn/Bing-Wallpaper-Action/main/data/zh-CN_all.json');
|
||||
var data = await response.json();
|
||||
var images = data.data.map(image => image.url);
|
||||
var backgroundDiv = document.getElementById('background');
|
||||
if (images.length > 0) {
|
||||
backgroundDiv.style.backgroundImage = 'url(' + images[0] + ')';
|
||||
backgroundDiv.style.backgroundImage = 'url(https://www.bing.com/' + images[0] + ')';
|
||||
}
|
||||
let index = 0;
|
||||
let currentBackgroundDiv = backgroundDiv;
|
||||
setInterval(() => {
|
||||
const nextIndex = (index + 1) % images.length;
|
||||
const nextBackgroundDiv = document.createElement('div');
|
||||
nextBackgroundDiv.className = 'background next';
|
||||
nextBackgroundDiv.style.backgroundImage = 'url(' + images[nextIndex] + ')';
|
||||
document.body.appendChild(nextBackgroundDiv);
|
||||
nextBackgroundDiv.style.opacity = 0;
|
||||
setTimeout(() => {
|
||||
nextBackgroundDiv.style.opacity = 1;
|
||||
}, 50);
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(currentBackgroundDiv);
|
||||
currentBackgroundDiv = nextBackgroundDiv;
|
||||
index = nextIndex;
|
||||
}, 1000);
|
||||
const nextIndex = (index + 1) % images.length;
|
||||
const nextBackgroundDiv = document.createElement('div');
|
||||
nextBackgroundDiv.className = 'background next';
|
||||
nextBackgroundDiv.style.backgroundImage = 'url(https://www.bing.com/' + images[nextIndex] + ')';
|
||||
document.body.appendChild(nextBackgroundDiv);
|
||||
nextBackgroundDiv.style.opacity = 0;
|
||||
setTimeout(() => {
|
||||
nextBackgroundDiv.style.opacity = 1;
|
||||
}, 50);
|
||||
setTimeout(() => {
|
||||
document.body.removeChild(currentBackgroundDiv);
|
||||
currentBackgroundDiv = nextBackgroundDiv;
|
||||
index = nextIndex;
|
||||
if(index>10)index=0;// 只取前十张
|
||||
}, 1000);
|
||||
}, 5000);
|
||||
|
||||
}
|
||||
|
||||
$(document).ready(function() {
|
||||
setBackgroundImages();// 设置背景
|
||||
// 初始化时显示格式提示
|
||||
@ -286,44 +294,44 @@ $(document).ready(function () {
|
||||
var fileIndex = 0;
|
||||
function uploadNextFile() {
|
||||
if (fileIndex < files.length) {
|
||||
var formData = new FormData();
|
||||
formData.append('file', files[fileIndex]);
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", '', true);
|
||||
var startTime;
|
||||
xhr.upload.addEventListener('progress', function (evt) {
|
||||
if (evt.lengthComputable) {
|
||||
if (!startTime) startTime = new Date();
|
||||
var percentComplete = Math.round((evt.loaded / evt.total) * 100);
|
||||
var elapsedTime = (new Date() - startTime) / 1000;
|
||||
var speed = (evt.loaded / 1024 / 1024) / elapsedTime;
|
||||
var fileRow = $('#file-row-' + fileIndex);
|
||||
fileRow.find('.progress-status').text(` ${speed.toFixed(2)} MB/s`);
|
||||
fileRow.find('.progress').show();
|
||||
fileRow.find('.progress-bar').css('width', percentComplete + '%').text(percentComplete + '%');
|
||||
var container = $('#fileList');
|
||||
var targetRow = $('#file-row-' + fileIndex);
|
||||
var targetTop = targetRow[0].offsetTop;
|
||||
var containerHeight = container.height();
|
||||
var rowHeight = targetRow.outerHeight();
|
||||
var scrollTo = targetTop - (containerHeight / 1) + (rowHeight / 2);
|
||||
scrollTo = Math.max(0, Math.min(scrollTo, container[0].scrollHeight - containerHeight));
|
||||
container.stop().animate({ scrollTop: scrollTo }, 200);
|
||||
if (percentComplete === 100) {
|
||||
setTimeout(function () {
|
||||
var formData = new FormData();
|
||||
formData.append('file', files[fileIndex]);
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("POST", '', true);
|
||||
var startTime;
|
||||
xhr.upload.addEventListener('progress', function (evt) {
|
||||
if (evt.lengthComputable) {
|
||||
if (!startTime) startTime = new Date();
|
||||
var percentComplete = Math.round((evt.loaded / evt.total) * 100);
|
||||
var elapsedTime = (new Date() - startTime) / 1000;
|
||||
var speed = (evt.loaded / 1024 / 1024) / elapsedTime;
|
||||
var fileRow = $('#file-row-' + fileIndex);
|
||||
fileRow.find('.progress-status').text(` ${speed.toFixed(2)} MB/s`);
|
||||
fileRow.find('.progress').show();
|
||||
fileRow.find('.progress-bar').css('width', percentComplete + '%').text(percentComplete + '%');
|
||||
var container = $('#fileList');
|
||||
var targetRow = $('#file-row-' + fileIndex);
|
||||
var targetTop = targetRow[0].offsetTop;
|
||||
var containerHeight = container.height();
|
||||
var rowHeight = targetRow.outerHeight();
|
||||
var scrollTo = targetTop - (containerHeight / 1) + (rowHeight / 2);
|
||||
scrollTo = Math.max(0, Math.min(scrollTo, container[0].scrollHeight - containerHeight));
|
||||
container.stop().animate({ scrollTop: scrollTo }, 200);
|
||||
if (percentComplete === 100) {
|
||||
setTimeout(function () {
|
||||
if (xhr.readyState !== XMLHttpRequest.DONE) {
|
||||
fileRow.find('.progress-status').text('处理中请稍等');
|
||||
}
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||
var fileRow = $('#file-row-' + fileIndex);
|
||||
if (xhr.status === 200) {
|
||||
var result = JSON.parse(xhr.responseText);
|
||||
if (result.upload_url) {
|
||||
}, 100);
|
||||
}
|
||||
}
|
||||
}, false);
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState === XMLHttpRequest.DONE) {
|
||||
var fileRow = $('#file-row-' + fileIndex);
|
||||
if (xhr.status === 200) {
|
||||
var result = JSON.parse(xhr.responseText);
|
||||
if (result.upload_url) {
|
||||
uploadedLinks.push(result.upload_url);
|
||||
fileRow.find('.progress-status').text('处理完成');
|
||||
fileRow.find('.progress').hide();
|
||||
@ -336,33 +344,33 @@ if (xhr.status === 200) {
|
||||
fileRow.find('.progress-status').text('成功上传');
|
||||
}, 100);
|
||||
showLinkOutput();
|
||||
} else if (result.error) {
|
||||
} else if (result.error) {
|
||||
fileRow.find('.progress-status').text('上传失败: ' + result.error);
|
||||
$('#statusOutput').text('上传中断: ' + result.error);
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
fileRow.find('.progress-status').text('错误信息: ' + xhr.statusText);
|
||||
$('#statusOutput').text('上传中断: ' + xhr.statusText);
|
||||
return;
|
||||
}
|
||||
fileIndex++;
|
||||
uploadNextFile();
|
||||
}
|
||||
};
|
||||
xhr.send(formData);
|
||||
}
|
||||
} else {
|
||||
fileRow.find('.progress-status').text('错误信息: ' + xhr.statusText);
|
||||
$('#statusOutput').text('上传中断: ' + xhr.statusText);
|
||||
return;
|
||||
}
|
||||
fileIndex++;
|
||||
uploadNextFile();
|
||||
}
|
||||
};
|
||||
xhr.send(formData);
|
||||
} else {
|
||||
$('#statusOutput').text('上传任务操作完成');
|
||||
$('#files').val(''); // 清空文件选择
|
||||
$('#statusOutput').text('上传任务操作完成');
|
||||
$('#files').val(''); // 清空文件选择
|
||||
}
|
||||
$('#statusOutput').text(`当前状态: 正在上传 ${files[fileIndex].name}`);
|
||||
}
|
||||
uploadNextFile();
|
||||
});
|
||||
function showLinkOutput() {
|
||||
$('.link-output').show();
|
||||
$('#linkText').val(uploadedLinks.join('\n')); // 显示所有链接
|
||||
$('#linkText').scrollTop($('#linkText')[0].scrollHeight);
|
||||
$('.link-output').show();
|
||||
$('#linkText').val(uploadedLinks.join('\n')); // 显示所有链接
|
||||
$('#linkText').scrollTop($('#linkText')[0].scrollHeight);
|
||||
}
|
||||
function showAlert(message) {
|
||||
var tooltip = document.createElement('div');
|
||||
@ -474,4 +482,4 @@ uploadNextFile();
|
||||
});
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
</html>
|
Loading…
x
Reference in New Issue
Block a user