Guest User

Untitled

a guest
Sep 27th, 2012
333
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.35 KB | None | 0 0
  1. <?php
  2. /*
  3. Template Name: DL Processing
  4. */
  5. ?>
  6.  
  7. <?php get_header(); ?>
  8.  
  9. <?
  10.  
  11. $id = $_GET['dl_id'];
  12.  
  13. if ( !empty($id) ) {
  14.  
  15. $valid_count = getDownloadCount($id);
  16.  
  17. if ( $valid_count > 0) {
  18. serveFile();
  19. }
  20.  
  21. }
  22.  
  23. /****
  24. *
  25. * Checks the download count for the corresponding file ID.
  26. *
  27. ****/
  28.  
  29. function getDownloadCount($id) {
  30. $current_user = wp_get_current_user();
  31. $user_id = $current_user->ID;
  32.  
  33. $download_counter = get_user_meta($user_id, 'download_count_'.$id, true);
  34.  
  35. if ( !empty($download_counter) ) {
  36. return $download_counter;
  37. } else {
  38. return false;
  39. }
  40. }
  41.  
  42. /****
  43. *
  44. * Serve the current file ID.
  45. *
  46. ****/
  47.  
  48. function serveFile() {
  49.  
  50. $path = 'https://docs.google.com/uc?export=download&id=0B3o97jD7AM7lVHc3bGdoSW5sRVk'; // the file made available for download via this PHP file
  51.  
  52. ob_start();
  53. header("Pragma: public");
  54. header("Expires: 0");
  55. header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
  56. header("Cache-Control: public");
  57. header("Content-Description: File Transfer");
  58. header("Content-Type: application/force-download");
  59. header("Content-Type: application/octet-stream");
  60. header('Content-Disposition: attachment; filename=derp.rar');
  61. header("Content-Transfer-Encoding: binary\n");
  62. ob_end_clean();
  63.  
  64. readfile($path); // outputs the content of the file
  65.  
  66. }
  67.  
  68. ?>
  69.  
  70. <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment