I\'m trying to provide a simple download using AJAX POST request. A user clicks a and the download begins (or a download dialog shows up, depending
You don't download the file using AJAX.
You just have to give the URL like but the problem is that you have to force download using headers and
URL Rewriting
to intercept the requests:
In case of an image:
$filename = basename($_GET['img']); // don't accept other directories
$size = @getimagesize($filename);
$fp = @fopen($filename, "rb");
if ($size && $fp)
{
header("Content-type: {$size['mime']}");
header("Content-Length: " . filesize($filename));
header("Content-Disposition: attachment; filename=$filename");
header('Content-Transfer-Encoding: binary');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
fpassthru($fp);
exit;
}
In this case.. the URL will not be changed (I think this is what you want)