<?php
//result Sheet view code
  if (isset($_GET['successrate_id '])) {
   $id = $_GET['successrate_id '];

   // fetch file to download from database
   $sql = "SELECT * FROM successrate WHERE successrate_id =$id";
   $result = mysqli_query($con, $sql);

   $file = mysqli_fetch_assoc($result);
   $filepath = 'upload/' . $file['images1'];

   if (file_exists($filepath)) {
       header('Content-Description: File Transfer');
       header('Content-Type: application/pdf');
       header('Content-Disposition: inline; filename=' . basename($filepath));
       header('Content-Transfer-Encoding: binary'); 
       header('Expires: 0');
       header('Cache-Control: must-revalidate');
       header('Pragma: public');
       header('Content-Length: ' . filesize('upload/' . $file['images1']));
       readfile('upload/' . $file['images1']);

       // Now update downloads count
       $newCount = $file['downloads'] + 1;
       $updateQuery = "UPDATE successrate SET downloads=$newCount WHERE successrate_id =$id";
       mysqli_query($con, $updateQuery);
       exit;
   }

}
