I've a form on submit I call images from DB against id
Then I follow php.net guide to download image. file downloaded successfully.
Now after downloading image or file I want to refresh/redirect to the same page to get downloads counts.
if (isset($_POST['download']) && $_POST['download'] =='click')
{
$sqlone = "Select image from products where products.id='$product_id'";
$run_sqlone = mysqli_query($con,$sqlone);
$fech_file = mysqli_fetch_array($run_sqlone);
$filenmae = $fech_file['image'];
$path = 'images/products/'.$fech_file['image'];
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($path));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($path);
$insertquery = "INSERT INTO
downloads
(product_id,
download_by)
values
(".$product_id.",
'".$user."')";
$run_insert = mysqli_query($con, $insertquery);
header('Location:product-detail.php?pcode='.$decrypt_id);
exit;
}
I tried using ob_start() in the beginning of page by doing so I did not able o download file.
Please Guide me accordingly.