function download_open_export_file( $filename ) { $filepath = \PressBooks\Export\Export::getExportFolder() . $filename; if ( ! is_readable( $filepath ) ) { // Cannot read file wp_die( __( 'File not found', 'pressbooks-textbook' ) . ": $filename", '', array( 'response' => 404 ) ); } // Force download set_time_limit( 0 ); header( 'Content-Description: File Transfer' ); header( 'Content-Type: ' . \Pressbooks\Export\Export::mimeType( $filepath ) ); header( 'Content-Disposition: attachment; filename="' . $filename . '"' ); header( 'Content-Transfer-Encoding: binary' ); header( 'Expires: 0' ); header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); header( 'Pragma: public' ); header( 'Content-Length: ' . filesize( $filepath ) ); @ob_clean(); flush(); while ( @ob_end_flush() ); // Fix out-of-memory problem readfile( $filepath ); exit; }