Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

360
Views
descargue el archivo zip en php y ajax sin location.href

Estoy creando un sistema de descarga de archivos zip en php con jquery ajax. Cuando el usuario hace clic en el botón de descarga, la solicitud va al servidor y devuelve el nombre del archivo. Puedo descargar el archivo, pero muestra el nombre del archivo completo junto con la ruta del archivo en la consola. No quiero esto.

 <button onclick="checkPayment(this.id)" id="filetoDownload_1">Download File</button>

JavaScript

 function checkPayment(data){ $.ajax({ type: 'post', url: '../download.php', data: data, async: false, success: function(result) { let returnkd = JSON.parse(result); if(returnkd["status"]){ $("#success").html(`<div class="card"><div class="card-body bg-white text-black">Download will start soon...</div></div>`); setTimeout(() => { window.location.href = returnkd["filename"]; }, 2000); }else{ $("#error").html(`<div class="card"><div class="card-body bg-white">Something wents wrong... contact admin</div></div>`); } } }); }

PHP

 // wothout header if(isset($_POST)){ some code return array("status"=>true,"filename"=>"../folder/filename.zip"); } // with header if(isset($_POST)){ some code here downloadFile($filename); return array("status"=>true,"filename"=>"../folder/filename.zip"); } function downloadFile($filename) { $filename = $filename; $filepath = "../".$filename; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-type: application/octet-stream"); header('Content-Disposition: attachment; filename="' . $filename . '"'); header("Content-Transfer-Encoding: binary"); header("Content-Length: " . filesize($filepath)); ob_end_flush(); @readfile($filepath); }

cómo descargar un archivo sin redirigir window.location.href o mostrar la ruta del archivo en la consola. He probado el encabezado php pero no funciona.

over 4 years ago · Santiago Trujillo
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!