Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
<?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