【问题标题】:POST http://127.0.0.1:5500/upload.php net::ERR_ABORTED 405 (Method Not Allowed)POST http://127.0.0.1:5500/upload.php net::ERR_ABORTED 405(方法不允许)
【发布时间】:2023-01-21 11:27:25
【问题描述】:

我正在尝试制作一个文件上传页面,但遇到了这个问题 POST http://127.0.0.1:5500/upload.php net::ERR_ABORTED 405(不允许的方法)

上传.js

const mainform = document.getElementById('mainform');
const inpFile = document.getElementById('inpFile');


mainform.addEventListener('submit', e => {

    e.preventDefault();


    const endpoint = 'upload.php';

    const formData = new FormData();


    formData.append('inpFile', inpFile.files[0]);


    fetch(endpoint, {
        method:"POST",
        body: formData
    }).catch(console.error);
});

上传.php

<?php

$targetPath = 'videos/' . basename($_FILES[inpFile]['name']);
move_uploaded_file($_FILES['inpFile']['tmp_name'], $targetPath);

【问题讨论】:

  • 仅供参考,$_FILES[inpFile]['name']应该是$_FILES['inpFile']['name']
  • @brombeer 还是不行

标签: javascript php


【解决方案1】:

您不能以这种方式更新 JSON 文件,但您可以使用数据库或在节点服务器 (node.js) 的帮助下应用相同的代码

【讨论】:

    猜你喜欢
    • 2018-12-20
    • 2017-10-16
    • 2014-05-23
    • 2021-09-09
    • 2014-06-22
    • 1970-01-01
    • 1970-01-01
    • 2015-11-16
    • 2016-05-15
    相关资源
    最近更新 更多