Advertisement
Guest User

Untitled

a guest
Jul 29th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.37 KB | None | 0 0
  1. <?php
  2.  
  3.  
  4. include('Connection.php');
  5.  
  6. class DownloadClass
  7. {
  8.  
  9.     public function __construct()
  10.     {
  11.  
  12.         if (isset($_GET['id'], $_GET['file'])) {
  13.             $query = Connection::DB()->query("SELECT filename, uid FROM files WHERE uid = '" . Connection::DB()->real_escape_string($_GET['id']) . "' AND filename = '". Connection::DB()->real_escape_string($_GET['file']) ."'");
  14.             $fquery = $query->fetch_object();
  15.  
  16.             if ($_GET['id'] == $fquery->uid AND $_GET['file'] == $fquery->filename) {
  17.                 return $this->Download($_GET['id'], $_GET['file']);
  18.             } else {
  19.                 return exit;
  20.             }
  21.         } else {
  22.             Header('Location: index.php');
  23.         }
  24.     }
  25.  
  26.     public function Download($fileid, $file)
  27.     {
  28.         $filedir = 'files/' . $fileid . '/' . $file;
  29.  
  30.         $basename = basename($filedir);
  31.  
  32.         header('Content-Description: File Transfer');
  33.         header('Content-Type: application/octet-stream');
  34.         header('Content-Disposition: attachment; filename="' . $basename . '"');
  35.         header('Content-Transfer-Encoding: binary');
  36.         header('Connection: Keep-Alive');
  37.         header('Expires: 0');
  38.         header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
  39.         header('Pragma: public');
  40.  
  41.         set_time_limit(0);
  42.         readfile($file);
  43.  
  44.  
  45.     }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement