dede关于上传图片失败和无法上传图片的两个错误

本文详细介绍了在创建/uploads/目录和/uploads/allimg/目录时遇到的问题,以及如何解决图片或文件选择窗口乱码及文章缩略图上传失败的情况。

1,创建/uploads/目录,该目录不存在时图片或者文件选择窗口打开会乱码

2,创建/uploads/allimg/目录,不存在时候,文章缩略图会上传失败

下面是两个html代码: <!DOCTYPE html> <html lang="zh-CN"> <head> <meta charset="UTF-8"> <title>jQuery文件上传示例</title> <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script> </head> <body> <input type="file" id="fileInput"> <button id="uploadBtn">上传文件</button> <div id="status"></div> <script> $(document).ready(function() { $("#uploadBtn").click(function() { const fileInput = $("#fileInput")[0]; if (!fileInput.files.length) { $("#status").text("请选择文件").css("color", "red"); return; } const formData = new FormData(); formData.append("file", fileInput.files[0]); $.ajax({ url: "https://your-api-endpoint.com/upload", // 替换为实际API地址 type: "POST", data: formData, headers: { "Authorization": "Bearer your-access-token", // 认证头 "X-Custom-Header": "CustomValue" // 自定义头 }, processData: false, // 禁用数据处理 contentType: false, // 禁用内容类型设置 beforeSend: function() { $("#status").text("上传中...").css("color", "blue"); }, success: function(response) { $("#status").text("上传成功: " + response.message).css("color", "green"); }, error: function(xhr) { $("#status").text("上传失败: " + xhr.statusText).css("color", "red"); } }); }); }); </script> </body> </html> <!DOCTYPE html> <html lang="zh-Hans"> <head> <meta charset="UTF-8"> <title>自定义文件上传按钮</title> <style> .file-input { display: none; } .custom-button { padding: 5px 10px; background: #00b0f0; color: #FFF; border: none; border-radius: 5px; cursor: pointer; } </style> </head> <body> <input type="file" id="fileInput" class="file-input"> <button class="custom-button" onclick="document.getElementById('fileInput').click()">上传文件</button> <span id="fileName">none</span> <script> document.getElementById('fileInput').addEventListener('change', function () { const fileName = document.getElementById('fileName'); fileName.textContent = this.files.length > 0 ? this.files[0].name : 'none'; }); </script> </body> </html> 要求合并两段代码,实现文件上传,不要求美观,越简洁越好
最新发布
06-14
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值