PHP 没有阅读 ajax 和 JQuery 发送的我的文件

PHP not reading my files sent by ajax with JQuery

所以我有这个问题,我不可能 read/save 文件 AJAX/JQuery 我正在使用这个

发送

<form class='file'>
 <input type='file' class='file_upload' name='def' required/>
 <input type='submit' value="Wyślij">
</form>

这是我尝试发送 JQuery 内容:

$(document).ready(function(){
 $("form.file").unbind().on("submit",function(event){
  $(this).find('input[type=submit]').attr('disabled', 'disabled');
  event.preventDefault();
  $(this).find(".file_upload").each(function(){
   sendFile(this.files[0]);
  });
  
  $(this).parent().remove();
 });
});


function sendFile(file){
 $.ajax({
  type: 'post',
  url:'sayv.php?name='+file.name,
  data:file,
  processData: false,
     contentType: file.type,
  success: function(data){
   console.log(data);
  }
   });
}

而且,PHP 无论如何我都无法阅读它, $_FILES 是空的,$_POST 也是...

由于您发送的是裸文件,即未包含在表单数据对象中的文件,因此它将成为请求正文。使用 file_get_contents('php://input'); 阅读。

file_put_contents('filename.ext', file_get_contents('php://input'));