Skip to content

Instantly share code, notes, and snippets.

@shrimp2t
Last active June 9, 2018 13:51
Show Gist options
  • Save shrimp2t/39ecdf0d1f7ad3924a6cf16b995d9c2a to your computer and use it in GitHub Desktop.
Save shrimp2t/39ecdf0d1f7ad3924a6cf16b995d9c2a to your computer and use it in GitHub Desktop.
<?php
// Set the file size header
header( "Content-Length: " . @filesize( $file_path ) );
// Now deliver the file based on the kind of software the server is running / has enabled
if ( stristr( getenv( 'SERVER_SOFTWARE' ), 'lighttpd' ) ) {
header( "X-LIGHTTPD-send-file: $file_path" );
} elseif ( $direct && ( stristr( getenv( 'SERVER_SOFTWARE' ), 'nginx' ) || stristr( getenv( 'SERVER_SOFTWARE' ), 'cherokee' ) ) ) {
// We need a path relative to the domain
$redirect_path = '/' . str_ireplace( realpath( $_SERVER['DOCUMENT_ROOT'] ), '', $file_path );
$redirect_path = apply_filters( 'edd_sl_accel_redirect_path', $redirect_path, $file_path );
header( "X-Accel-Redirect: $redirect_path" );
}
if( $direct ) {
edd_deliver_download( $file_path );
} else {
// The file supplied does not have a discoverable absolute path
edd_deliver_download( $requested_file, true );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment