更新 index.php
修正,去除多余代码。
This commit is contained in:
parent
1ec7d4ddce
commit
0df055216c
51
index.php
51
index.php
@ -3,11 +3,11 @@ $base_dir='/o/';//以/即结束即可
|
||||
$user="chate.store";// 用户名
|
||||
$pwd="123456";// 密码,请记得频繁更换
|
||||
|
||||
$authorization = false;
|
||||
$auth = false;
|
||||
if ($_SERVER['PHP_AUTH_USER'] == $user && $_SERVER['PHP_AUTH_PW'] == $pwd){
|
||||
$authorization = true;
|
||||
$auth = true;
|
||||
}
|
||||
if(!$authorization){
|
||||
if(!$auth){
|
||||
// 没登录成功,弹出要求输入用户名和密码窗口
|
||||
header("WWW-Authenticate:Basic realm='Private'");
|
||||
header('HTTP/1.0 401 Unauthorized');
|
||||
@ -28,7 +28,11 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
|
||||
// 兼容跨平台路径
|
||||
$md5 = md5_file($file_tmp);
|
||||
$upload_dir = getcwd() . $base_dir . substr($md5,0,1).'/'.substr($md5,1,1);
|
||||
$dir1 = substr($md5,0,1);
|
||||
$dir2 = substr($md5,1,1);
|
||||
$path = getcwd();
|
||||
$upload_dir = $path . $base_dir .$dir1 .'/'. $dir2;
|
||||
$upload_parent_dir = $path . $base_dir .$dir1 ;
|
||||
// 检查并创建目录
|
||||
if (!is_dir($upload_dir)) {
|
||||
if (!mkdir($upload_dir, 0777, true) && !is_dir($upload_dir)) {
|
||||
@ -37,7 +41,9 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
}
|
||||
// 开始创建index.html
|
||||
file_put_contents($upload_dir .'/index.html', 'no access');
|
||||
file_put_contents( getcwd() . $base_dir . substr($md5,0,1). '/index.html', 'no access');
|
||||
if(!file_exists($upload_parent_dir. '/index.html')){
|
||||
file_put_contents( $upload_parent_dir. '/index.html', 'no access');
|
||||
}
|
||||
}
|
||||
|
||||
// 根据文件内容生成MD5文件名,这样可以排除重复上传
|
||||
@ -45,7 +51,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
// 这里判断下重复文件不移动文件
|
||||
$target_file=$upload_dir . '/' .$FileName;
|
||||
if (file_exists($target_file) || move_uploaded_file($file_tmp, $target_file)) {
|
||||
echo '{"upload_url":"http://'.$_SERVER['HTTP_HOST'] . $base_dir . substr($md5,0,1). '/' .substr($md5,1,1) .'/'. $FileName.'"}';
|
||||
echo '{"upload_url":"http://'.$_SERVER['HTTP_HOST'] . $base_dir . $dir1. '/' .$dir2 .'/'. $FileName.'"}';
|
||||
} else {
|
||||
echo '{"error":"写入失败,无法保存文件"}';
|
||||
}
|
||||
@ -148,25 +154,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
justify-content: flex-end; /* 使按钮靠右对齐 */
|
||||
margin-top: 10px; /* 添加上边距 */
|
||||
}
|
||||
[url=home.php?mod=space&uid=945662]@media[/url] (max-width: 600px) {
|
||||
.container {
|
||||
width: 100%;
|
||||
padding: 0 10px;
|
||||
}
|
||||
.file-name {
|
||||
width: 100px;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
.progress-status {
|
||||
display: none;
|
||||
}
|
||||
.btn-download, .btn-copy {
|
||||
width: 40px;
|
||||
margin-left: 5px;
|
||||
}
|
||||
}
|
||||
|
||||
.nav {
|
||||
display: flex;
|
||||
justify-content: center; /* 居中对齐 */
|
||||
@ -179,11 +167,12 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
<div class="container">
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="card-title text-center" style="font-weight: bold;">一个简单的图床</h4>
|
||||
<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, image/bmp, image/svg+xml" required>
|
||||
<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>
|
||||
@ -197,7 +186,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
|
||||
<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, BMP, SVG 最大上传:<?php echo ini_get('upload_max_filesize');?></h6>
|
||||
<h6 id="formatHint" class="card-title text-center">支持格式: JPEG, PNG, GIF, WEBP, AVIF 最大上传:<?php echo ini_get('upload_max_filesize');?></h6>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@ -233,11 +222,11 @@ $(document).ready(function () {
|
||||
clearOutput();
|
||||
var files = this.files;
|
||||
// 允许的文件类型
|
||||
var validFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif', 'image/bmp', 'image/svg'];
|
||||
var validFormats = ['image/jpeg', 'image/png', 'image/gif', 'image/webp', 'image/avif'];
|
||||
var validFiles = Array.from(files).filter(file => validFormats.includes(file.type));
|
||||
|
||||
if (validFiles.length === 0) {
|
||||
showAlert('请选择有效的图片文件(JPEG, PNG, GIF,WEBP,AVIF,BMP,SVG)!');
|
||||
showAlert('请选择有效的图片文件(JPEG, PNG, GIF,WEBP,AVIF)!');
|
||||
$('#files').val(''); // 清空文件选择
|
||||
return;
|
||||
}
|
||||
@ -336,12 +325,10 @@ $(document).ready(function () {
|
||||
uploadNextFile();
|
||||
});
|
||||
function showLinkOutput() {
|
||||
if (uploadedLinks.length > 1) {
|
||||
$('.link-output').show();
|
||||
$('#linkText').val(uploadedLinks.join('\n')); // 显示所有链接
|
||||
$('#linkText').scrollTop($('#linkText')[0].scrollHeight);
|
||||
}
|
||||
}
|
||||
function showAlert(message) {
|
||||
var tooltip = document.createElement('div');
|
||||
tooltip.style.position = 'fixed';
|
||||
|
Loading…
x
Reference in New Issue
Block a user