Advertisement
Guest User

Untitled

a guest
Aug 8th, 2017
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. <?php
  2. //This is the download page.
  3. function get_path($conn, $doc_id)
  4. {
  5. $q = "Select * from docs where docID = $doc_id";
  6. if($res = mysqli_query($conn, $q))
  7. {
  8. while($row = mysqli_fetch_assoc($res))
  9. {
  10. return $row['path'];
  11. }
  12. }
  13. return false;
  14. }
  15.  
  16.  
  17. $doc_id = $_POST['docID'];
  18.  
  19. $servername = "localhost";
  20. $username = "Bl4de";
  21. $password = "Bl4de-1337";
  22. $dbname = "web-content";
  23.  
  24.  
  25.  
  26.  
  27. $conn = mysqli_connect($servername, $username, $password, $dbname);
  28. if (!$conn)
  29. {
  30. echo "Some error occurred.";
  31. }
  32. else
  33. {
  34. $my_file = get_path($conn, $doc_id);
  35. header('Content-Type: application/octet-stream');
  36. header("Content-Transfer-Encoding: Binary");
  37. header("Content-disposition: attachment; filename=\"" . basename($my_file) . "\"");
  38. readfile($my_file);
  39. }
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement