Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Template Name: DL Processing
- */
- ?>
- <?php get_header(); ?>
- <?
- $id = $_GET['dl_id'];
- if ( !empty($id) ) {
- $valid_count = getDownloadCount($id);
- if ( $valid_count > 0) {
- serveFile();
- }
- }
- /****
- *
- * Checks the download count for the corresponding file ID.
- *
- ****/
- function getDownloadCount($id) {
- $current_user = wp_get_current_user();
- $user_id = $current_user->ID;
- $download_counter = get_user_meta($user_id, 'download_count_'.$id, true);
- if ( !empty($download_counter) ) {
- return $download_counter;
- } else {
- return false;
- }
- }
- /****
- *
- * Serve the current file ID.
- *
- ****/
- function serveFile() {
- $path = 'https://docs.google.com/uc?export=download&id=0B3o97jD7AM7lVHc3bGdoSW5sRVk'; // the file made available for download via this PHP file
- ob_start();
- header("Pragma: public");
- header("Expires: 0");
- header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
- header("Cache-Control: public");
- header("Content-Description: File Transfer");
- header("Content-Type: application/force-download");
- header("Content-Type: application/octet-stream");
- header('Content-Disposition: attachment; filename=derp.rar');
- header("Content-Transfer-Encoding: binary\n");
- ob_end_clean();
- readfile($path); // outputs the content of the file
- }
- ?>
- <?php get_footer(); ?>
Advertisement
Add Comment
Please, Sign In to add comment