php - 表单不上传文件
问题描述
我在上传 img 时遇到问题,php 大喊 $_FILES 为空或更具体:
Notice: Undefined index: newAvatar [...]
Notice: Trying to access array offset on value of type null [...]
这是我的表格:
<form action="updateAvatar.php" method="post" id="updateAvatarForm" enctype=”multipart/form-data”>
<div class="changeAvatar">
<div class="avatar">
<img src=<?php echo ($_SESSION['profile'] != NULL) ? base64_encode($_SESSION['profile']) : "../static/img/blankProfilePic.svg";?> alt="" id="avatarPreview">
<input type="file" name="newAvatar" id="newAvatar">
<img src="../static/img/changeProfilePic.svg" alt="" id="changeAvatar">
</div>
</div>
</form>
和简单的 php 图像打印机:
<?php
echo '<img src='.$_FILES["newAvatar"]["name"].'>';
?>
表单由 js 中的 eventListener 提交:
newAvatar.addEventListener("change", ()=>{
updateAvatarForm.submit()
});
我试图在表单中添加一些诸如“ajax-something”之类的道具,在js中设置超时因为我认为提交可能触发得太快但我被卡住了,我尝试过的一切都不起作用......
如果有人可以提供帮助,我将不胜感激,对不起我的英语不是我的母语。
解决方案
推荐阅读
- html - Bootstrap 4:尝试将卡片内的内容与右下角对齐
- c++ - 浮动结构是否有任何填充?
- azure - 如何在没有标签的情况下执行策略,任何作业都不会运行
- java - 使用主要活动 NoActionBar 的主题时不显示选项菜单按钮
- java - 在将图像传递给报告期间获取 IllegalArgumentException
- audio - 从 .m2ts 视频文件中删除音频流
- amazon-web-services - 将 IP 地址重定向到 AWS 上的子域
- django - Django Abstract Class 根据实际类改变行为
- html - 如何将侧边栏与一行的主要内容 div 垂直对齐
- java - 在 System.gc() 之后未释放 Java 弱引用