I have a JQuery form:
Code:
$("#download").live("submit", function () {
$.ajax({
type: "POST",
cache: false,
url: "download.php",
data: $(this).serialize(),
success: function (data) {
$('#result').html(data);
}
});
return false;
});
Which submits to a PHP file:
PHP Code:
<?php
$file = $_POST['file'];
$url = '/uploads/' . $file . '.zip';
header("Cache-Control: public");
header("Content-Description: File Transfer");
header("Content-Disposition: attachment; filename=x.zip");
header("Content-Type: application/zip");
header("Content-Transfer-Encoding: binary");
readfile( $url );
exit();
?>
Which outputs garbled text into my "#result" div. I'm positive that the PHP is executing properly, but how can I get JQuery to prompt the download instead of reading as text? When I delete "$('#result').html(data);" nothing happens at all, and I can't just link to the PHP file because the form submits file-specific info. Thanks ...