Guest User

Untitled

a guest
Mar 2nd, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.81 KB | None | 0 0
  1. <?php
  2.  
  3. require '/home/solidarity/kr/bbs/include/common.php';
  4.  
  5. $user="solidarity";
  6. $host="localhost";
  7. $password="hyuz";
  8. $database="dev";
  9.  
  10. $connection = mysql_connect($host,$user,$password)
  11. or die ("couldn't connect to server"); $db = mysql_select_db($database,$connection)
  12. or die ("Couldn't select database");
  13.  
  14. $query .= "SELECT donor FROM bbs_users WHERE id=".$pun_user['id'];
  15. $result = mysql_query($query, $connection) or die
  16. ("Could not execute query : $query ." . mysql_error());
  17.  
  18. $show = $_GET['show'];
  19. $ep = $_GET['ep'];
  20.  
  21. $directory = '/home/solidarity/private/krdl/';
  22.  
  23. $show2 = $show.'/';
  24.  
  25. // local file that should be send to the client
  26. $local_file = $ep;
  27.  
  28. $download = $directory.$show2.$local_file;
  29.  
  30. $size = intval(sprintf("%u", filesize($download)));
  31.  
  32. while($process=mysql_fetch_array($result)) {
  33.  
  34. $donor=$process["donor"];
  35.  
  36. if($donor=="1") {
  37.  
  38.     header('Content-Type: application/octet-stream');
  39.     header('Content-Disposition: attachment; filename='.basename($download));
  40.     header('Content-Transfer-Encoding: binary');
  41.     header('Cache-Control: private');
  42.     header('Content-Length: ' . filesize($download));
  43.     set_time_limit(300);
  44. // If it's a large file, readfile might not be able to do it in one go, so:
  45. $chunksize = 1 * (1024 * 1024); // how many bytes per chunk
  46. if ($size > $chunksize) {
  47.   $handle = fopen($download, 'rb');
  48.   $buffer = '';
  49.   while (!feof($handle)) {
  50.     $buffer = fread($handle, $chunksize);
  51.     echo $buffer;
  52.     ob_flush();
  53.     flush();
  54.   }
  55.   fclose($handle);
  56. } else {
  57.   readfile($download);
  58. }
  59. // Exit successfully. We could just let the script exit
  60. // normally at the bottom of the page, but then blank lines
  61. // after the close of the script code would potentially cause
  62. // problems after the file download.
  63. exit;
  64. }
  65. }
  66. ?>
Add Comment
Please, Sign In to add comment