Skip to content

Instantly share code, notes, and snippets.

@shadimanna
Created October 25, 2017 13:12
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 shadimanna/bfe5fa569da44e61f1ae81a17e408af7 to your computer and use it in GitHub Desktop.
Save shadimanna/bfe5fa569da44e61f1ae81a17e408af7 to your computer and use it in GitHub Desktop.
<?php
if ( ! defined( 'ABSPATH' ) ) exit; // Exit if accessed directly
// $file = sanitize_file_name( $_GET['path'] );
// sanitize path
$file = realpath( $_GET['path'] );
// echo $file;
if ( current_user_can( 'edit_shop_orders' ) && check_admin_referer( 'download-dhl-label' ) ) {
if( file_exists($file) ) {
// echo 'file exists';
// echo '<br/>';
// echo $file;
$file_info = pathinfo($file);
$ext = strtoupper($file_info['extension']);
// echo $ext['extension'];
// echo $ext;
$allowed_ext = array( 'PDF', 'PNG', 'ZPL' );
if( in_array($ext, $allowed_ext) ) {
// echo 'allowd';
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename="'.basename($file).'"');
header('Expires: 0');
header('Cache-Control: must-revalidate');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
readfile($file);
exit;
}
}
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment