Javascript:

var file = this.files[0]; if(!file) return; $.ajax({ type: 'POST', url: '/file.php', data: 'cover='+file, success: function(data){ console.log(data); }, error: function(){ alert('error'); } }); 

How to save a file on the server?

print_r($_FILES); I get Array ()

On print_r($_POST); I get Array ([cover] => [object File])

    1 answer 1

    If only for modern browsers (Chrome 10+, FF4 +, Safari 6+, Opera 12+, IE10 +), then so:

     var formData = new FormData; $.each(this.files, function (i, file){ formData.append('files[]', file); }); $.ajax({ url: '...', type: 'post', data: formData, contentType: false, processData: false, success: function (result){ /*__*/ } }); 

    For full support (up to IE6), I can offer the FileAPI library.