Skip to content

Instantly share code, notes, and snippets.

@codeboxr
Created July 17, 2013 09:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save codeboxr/6019221 to your computer and use it in GitHub Desktop.
Save codeboxr/6019221 to your computer and use it in GitHub Desktop.
### Function: Add Download Query Vars
add_filter('query_vars', 'cbreport_query_vars');
function cbreport_query_vars($public_query_vars) {
$public_query_vars[] = "report_ids";
return $public_query_vars;
}
add_action('template_redirect', 'reportdownload_file', 5);
function reportdownload_file() {
global $wpdb;
$report_ids = intval(get_query_var('report_ids'));
//slit with comman
//query posts,
//for each post
//get meta for the pdf file url
//so now we are in loop
// required for IE, otherwise Content-disposition is ignored
if(ini_get('zlib.output_compression')){
ini_set('zlib.output_compression', 'Off');
}
header($_SERVER['SERVER_PROTOCOL'].' 200 OK'); //added by me
header("Pragma: public");
header("Expires: 0");
header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
header("Content-Type: application/force-download");
header("Content-Type: application/octet-stream");
header("Content-Description: File Transfer");
header("Content-Type: application/download");
header("Content-Disposition: attachment; filename=".basename($file_name).";");
header("Content-Transfer-Encoding: binary");
header("Content-Length: ".filesize($file_path.$file_name));
ob_clean();
flush();
readfile($file_path.$file_name);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment