I got an empty file whenever i download any file. This is an php file where pateint can download his report by entering his appointment id and password.

<?php
error_reporting(0);
include'include/database.php';
if($_POST['sbutton'])

  {

    $appid=$_POST['apid'];
    $password=md5($_POST['pass']);
    $result=mysqli_query($conn,"select patientId from appointments where app_id='$appid'") or die(mysqli_error($conn));
    $row=mysqli_fetch_array($result);
    $result2=mysqli_query($conn,"select password from patients where id='".$row['patientId']."'") or die(mysqli_error($conn));
    $row2=mysqli_fetch_array($result2);
    if($row2['password']==$password)
    {
      $sql = "select * from reports where app_id='$appid'";
      $result = mysqli_query($conn,$sql);
      $num_rows = mysqli_num_rows($result);
      if($num_rows>0)
      {
      $row = mysqli_fetch_array($result);
      $filename="patientReport";
      header("Content-Type: application/pdf/jpg");
      header("Content-Length: " . strlen($row['image']));
      header("Content-Disposition: attachment; filename=\"" . $filename . ".rar\";");
      echo base64_decode($row['image']);
      }
        else {
        echo "<script>window.alert('Not yet Uploaded'); window.location.href='downloadreport.php';</script>";
      }
    }
    else
    {
      echo "<script>alert('Wrong Credentials');</script>";
    }


}
?>

Taking a look at this header:

header("Content-Type: application/pdf/jpg");
header("Content-Disposition: attachment; filename=\"" . $filename . ".rar\";");

What type of file are you trying to give to the user? Is it an application? A PDF? A jpg? A rar file?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.