Javascript将带有文件的数组发送到php


Javascript sending array with files to php

所以我发送了一个jquery对象,其中包含关于文件和实际$("#input").files[0]; item的一些信息。

jquery/javascript看起来如下:

$.ajax({
    url: '/upload/create',
    type: 'POST',
    dataType: 'json',
    data: JSON.stringify(data),
    success: function(msg) {
        alert(msg);
    }
});

数据变量是一个JQuery对象,它包含关于上传的文件和文件本身的信息(我认为),我只是在对象中传递了它。

有没有办法用PHP在服务器端提取并保存这个文件?

只需删除JSON.stringify()调用,您就可以了。data应该是一个对象,它被转换为PHP的关联$_POST$_GET数组,stringify将它转换为字符串。

data: data,