I'm creating a download page in PHP, which will display an alert box in Javascript IF the download file does not exist (when the user clicks a button for the corresponding product).
The PROBLEM is, once the user hits OK on the alert box, it navigates away from the current page (that lists the downloads). I want it to STAY on the same page with the SAME content to be displayed.
Full code:
<?php
$product = $_GET["p"];
$ChangeFileName = "";
if ($product == 'Product1')
{
$realFileName = "OriginalFileName.exe";
$ChangeFileName = "NewFileNameHere.exe";
}
elseif ($product == 'Product2')
{
$realFileName = "OriginalFileName.exe";
$ChangeFileName = "NewFileNameHere.exe";
}
else
{
echo '<script type="text/javascript">
alert("Sorry, there is no download available for this product! Please contact support.");
</script>';
exit;
}
$file = "downloads/".$realFileName;
$fp = fopen($file, 'rb');
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=$ChangeFileName");
header("Content-Length: " . filesize($file));
fpassthru($fp);
?>
exit;