getFile.php 857 B

123456789101112131415161718192021222324
  1. <?php
  2. if (isset($_GET["id"])) {
  3. include("../connectSQL_Component.php");
  4. $id = $_GET["id"];
  5. $file = "";
  6. $sql = "SELECT [file_path] FROM [BIMComponents].[dbo].[File_Table] WHERE [id] = " . $id . ";";
  7. $fetchResult = sqlsrv_query($conn, $sql);
  8. while ($row = sqlsrv_fetch_array($fetchResult, SQLSRV_FETCH_ASSOC)) {
  9. $file = "../../." . $row["file_path"];
  10. }
  11. sqlsrv_close($conn);
  12. if (file_exists($file)) {
  13. header('Content-Description: File Transfer');
  14. header('Content-Type: application/octet-stream');
  15. header('Content-Disposition: attachment; filename="' . basename($file) . '"');
  16. header('Expires: 0');
  17. header('Cache-Control: must-revalidate');
  18. header('Pragma: public');
  19. header('Content-Length: ' . filesize($file));
  20. readfile($file);
  21. exit;
  22. }
  23. }