<?php
//equipment view code
  if (isset($_GET['equip_id'])) {
   $id = $_GET['equip_id'];

   // fetch file to download from database
   $sql = "SELECT * FROM equipment WHERE equip_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 equipment SET downloads=$newCount WHERE equip_id=$id";
       mysqli_query($con, $updateQuery);
       exit;
   }

}
