简体   繁体   English

PHP 不想从 ajax 接收数据

[英]PHP doesn't want to recieve data from ajax

i want to create a formless drag and drop file upload using JavaScript's FormData, but PHP doesn't seem to be receiving the file.我想使用 JavaScript 的 FormData 创建无形式的拖放文件上传,但 PHP 似乎没有收到该文件。 Am i missing some request headers or something?我是否缺少一些请求标头或其他内容?

JavaScript: JavaScript:

if (item.kind === 'file') 
            {
                const file = item.getAsFile();
                const fileFormData = new FormData();
                fileFormData.append('file', file);
                $.ajax({
                    url: "backend/uploadFiles.php",
                    type: 'POST',
                    data: fileFormData,
                    cache: false,
                    contentType: false,
                    processData: false,
                    success: function (returndata) {
                        console.log(returndata);
                    }
                });

PHP: PHP:

<?php
var_dump($_POST);
var_dump($_GET);

PHP output: PHP output:

array(0) {
}
array(0) {

} }

Files are stored in $_FILES array.文件存储在 $_FILES 数组中。 $_FILES is array of items uploaded to the current script via the HTTP POST method. $_FILES 是通过 HTTP POST 方法上传到当前脚本的项目数组。 see https://www.php.net/manual/en/reserved.variables.files.php参见https://www.php.net/manual/en/reserved.variables.files.php

var_dump($_FILES)

and make sure that file_uploads is set to On in the php.ini file并确保在 php.ini 文件中将 file_uploads 设置为 On

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM