4
I am unable to upload some files with AJAX. I need to send 3 files with dynamically generated inputs, so I didn’t use the Multiple attribute.
Firing the event, I get to xhr.send(files), which does not "play" the PHP file.
Can 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
}
Got it right, boss. Thanks!
– michelmfreitas
@michelmforts :)
– 537mfb