<?php  
 include_once 'opendb.php';
 
  $ReqID=0; 
  if (isset($_POST["ReqID"]) )
   {       
              
             $ReqID=$_POST["ReqID"]; 
      //       $ReqID=1;
              $sql = "SELECT * FROM client_requests WHERE request_id = ".$ReqID.";";
              $result = $conn->query($sql);
              if ($row = mysqli_fetch_array($result,MYSQLI_ASSOC))
              { 
                      $fname=$row["file_name"];
                      $fdata=$row["file_data"];
                      //$fdata=stripcslashes($fdata);
                     
                       header('Content-Description: File Transfer');
                       header('Content-Type: application/pdf');
                         header('Content-Disposition: attachment; filename="request.pdf"');
                     //  header("Content-Disposition: attachment; filename=\"$fname\"");
                      // header('Content-Transfer-Encoding: binary');
                     //  header('Accept-Ranges: bytes');
                    //   header('Expires: 0');
                    //   header('Cache-Control: must-revalidate');
                    //   header('Pragma: public');
                       header('Content-Length: ' . strlen($fdata));
                       print $fdata;
                       exit;
               
              }
              else 
              {
                  echo( "Error getting file, invalid request id " . $ReqID);
              }
              $conn->close();
    
    }
    else 
    {
     echo "Error No parameters" .$ReqID;
    }
 ?>