Necesito recibir el archivo a través de XMLHttpRequest y luego guardar este archivo en un archivo .zip. Lo probé enviando la respuesta a través de XMLHttpRequest pero no funcionó muy bien, ¿alguien sabe cómo hacer esto? necesito descargar y no cargar archivo
$(".download_files").click(function () { let ajax = new XMLHttpRequest(); ajax.open("POST", "http://localhost/download.php"); ajax.onprogress = function (ev) { $(".total").text(ev.total); $(".loaded").text(ev.loaded); $(".p").text(Math.floor(ev.loaded / ev.total * 100)); } ajax.onloadend = function (ev) { let obj = this; if (obj.status === 200) { $(".create").show(); let ajaxCreate = new XMLHttpRequest(); ajaxCreate.open("POST", "test.php"); ajaxCreate.setRequestHeader('Content-type', 'application/x-www-form-urlencoded'); ajaxCreate.send("data=" + obj.response); console.log(obj.response); } else { alert("download error :/"); } } ajax.send(); });codigo PHP
<?php $data = $_POST['data']; $fopen = fopen(__DIR__."/downloads/".sha1(time()+mt_rand()).".zip", "w+"); fwrite($fopen, $_POST['data']); fclose($fopen);