title: How to get MIME Type of a file to be downloaded?
body: <p>I Have to download the listed file on click of the link, for whic I have used the below scripot, but I when the file gets dowloaded, it cannot idenetify the extension of downloaded file. So, How to get MIME Type of a file to be downloaded? _Please Help...</p>
  
  <pre><code>$filename = $_GET['val'];
           // Fetch the file info.
      $filePath = $_SERVER['DOCUMENT_ROOT'] . "dfms/images/uploads/".$filename;
  
  
      if(file_exists($filePath)) {
          echo $fileName = basename($filePath);
          $fileSize = filesize($filePath);
  
          // Output headers.
          header("Cache-Control: private");
          header("Content-Type: application/octet");
          header("Content-Length: ".$fileSize);
          header("Content-Disposition: attachment; filename=".$fileName);
  
          // Output file.
          readfile ($filePath);                   
          exit();
      }
      else {
          die('The provided file path is not valid.');
      }
  </code></pre>