I am not able to send some upload files with AJAX. I need to send 3 files with dynamically generated inputs, so I did not use the multiple attribute.
By firing the event, I get to the xhr.send (files), which does not "play" the PHP file.
Can you help me?
function UploadFile(file){
var files = file[0];
var xhr = new XMLHttpRequest();
var fd = new FormData();
fd.append( "arquivo", files, files.name );
xhr.open("POST", "Produtos/upload", true);
console.log(files.name); //imprime o nome certinho da imagem
xhr.setRequestHeader("X_FILENAME", files.name);
xhr.send(fb);
}
$(".btn-comprar").click(function (e) {
e.preventDefault();
var form = $("#upload");
var arquivos = $(".arquivos");
for (var i = 0; i < arquivos.length; i++) {
UploadFile(arquivos[i].files);
}
});
In PHP:
public function upload(){
$this->autoRender = false;
debug($_FILES); // nao imprime
echo "ok"; //nao imprime
}