Easy Digital Downloads
  • Package
  • Function
  • Tree

Packages

  • EDD
    • Admin
      • Actions
      • Add-ons
      • Dashboard
      • Discounts
      • Downloads
      • Export
      • Notices
      • Pages
      • Payments
      • Reports
      • Settings
      • System
      • Upgrades
      • Upload
      • Welcome
    • Cart
    • Checkout
    • Classes
      • API
      • Fees
      • HTML
      • Roles
      • Session
    • Emails
    • Functions
      • AJAX
      • Compatibility
      • Errors
      • Formatting
      • Install
      • Login
      • Taxes
      • Templates
    • Gateways
    • Logging
    • Payments
    • Shortcodes
    • Widgets

Functions

  • _edd_deprecated_function
  • edd_admin_downloads_icon
  • edd_allowed_mime_types
  • edd_block_attachments
  • edd_cart_discounts_html
  • edd_cart_has_discounts
  • edd_change_default_title
  • edd_cleanup_file_symlinks
  • edd_count_file_downloads_of_user
  • edd_count_purchases_of_customer
  • edd_decrease_earnings
  • edd_decrease_purchase_count
  • edd_deliver_download
  • edd_discount_exists
  • edd_discount_is_min_met
  • edd_discount_is_single_use
  • edd_discount_product_reqs_met
  • edd_display_cart_discount
  • edd_format_discount_rate
  • edd_get_actions
  • edd_get_average_monthly_download_earnings
  • edd_get_average_monthly_download_sales
  • edd_get_bundled_products
  • edd_get_cart_discounted_amount
  • edd_get_cart_discounts
  • edd_get_cart_discounts_html
  • edd_get_country_list
  • edd_get_currencies
  • edd_get_current_page_url
  • edd_get_default_labels
  • edd_get_discount
  • edd_get_discount_amount
  • edd_get_discount_by_code
  • edd_get_discount_code
  • edd_get_discount_expiration
  • edd_get_discount_id_by_code
  • edd_get_discount_max_uses
  • edd_get_discount_min_price
  • edd_get_discount_product_condition
  • edd_get_discount_product_reqs
  • edd_get_discount_start_date
  • edd_get_discount_type
  • edd_get_discount_uses
  • edd_get_discounted_amount
  • edd_get_discounts
  • edd_get_download
  • edd_get_download_earnings_stats
  • edd_get_download_file_url
  • edd_get_download_files
  • edd_get_download_final_price
  • edd_get_download_price
  • edd_get_download_sales_stats
  • edd_get_download_type
  • edd_get_file_ctype
  • edd_get_file_download_limit
  • edd_get_file_download_limit_override
  • edd_get_file_extension
  • edd_get_file_price_condition
  • edd_get_highest_price_option
  • edd_get_ip
  • edd_get_label_plural
  • edd_get_label_singular
  • edd_get_lowest_price_option
  • edd_get_php_arg_separator_output
  • edd_get_price_option_name
  • edd_get_product_notes
  • edd_get_provinces_list
  • edd_get_purchase_cc_info
  • edd_get_purchase_form_user
  • edd_get_states_list
  • edd_get_success_page_url
  • edd_get_symlink_dir
  • edd_get_symlink_url
  • edd_get_users_purchases
  • edd_get_variable_prices
  • edd_has_active_discounts
  • edd_has_purchases
  • edd_has_user_purchased
  • edd_has_variable_prices
  • edd_increase_discount_usage
  • edd_increase_earnings
  • edd_increase_purchase_count
  • edd_is_cc_verify_enabled
  • edd_is_discount_active
  • edd_is_discount_expired
  • edd_is_discount_maxed_out
  • edd_is_discount_not_global
  • edd_is_discount_started
  • edd_is_discount_used
  • edd_is_discount_valid
  • edd_is_file_at_download_limit
  • edd_is_func_disabled
  • edd_is_odd
  • edd_is_test_mode
  • edd_let_to_num
  • edd_load_admin_scripts
  • edd_load_scripts
  • edd_logged_in_only
  • edd_month_num_to_name
  • edd_no_guest_checkout
  • edd_no_redownload
  • edd_post_actions
  • edd_presstrends
  • edd_price
  • edd_price_range
  • edd_process_download
  • edd_process_purchase_form
  • edd_purchase_form_required_fields
  • edd_purchase_form_validate_agree_to_terms
  • edd_purchase_form_validate_cc
  • edd_purchase_form_validate_cc_zip
  • edd_purchase_form_validate_discounts
  • edd_purchase_form_validate_fields
  • edd_purchase_form_validate_gateway
  • edd_purchase_form_validate_guest_user
  • edd_purchase_form_validate_logged_in_user
  • edd_purchase_form_validate_new_user
  • edd_purchase_form_validate_user_login
  • edd_purchase_total_of_user
  • edd_query_vars
  • edd_readfile_chunked
  • edd_record_download_in_log
  • edd_record_sale_in_log
  • edd_register_and_login_new_user
  • edd_register_post_type_statuses
  • edd_register_styles
  • edd_remove_cart_discount
  • edd_remove_discount
  • edd_remove_download_logs_on_delete
  • edd_send_back_to_checkout
  • edd_send_to_success_page
  • edd_set_cart_discount
  • edd_set_file_download_limit_override
  • edd_setup_download_taxonomies
  • edd_setup_edd_post_types
  • edd_single_price_option_mode
  • edd_store_discount
  • edd_straight_to_checkout
  • edd_string_is_image_url
  • edd_unset_all_cart_discounts
  • edd_unset_cart_discount
  • edd_update_discount_status
  • edd_updated_messages
  • edd_validate_username
  • edd_verify_download_link
  • edd_version_in_header
  1 <?php
  2 /**
  3  * Process Download
  4  *
  5  * @package     EDD
  6  * @subpackage  Functions
  7  * @copyright   Copyright (c) 2013, Pippin Williamson
  8  * @license     http://opensource.org/licenses/gpl-2.0.php GNU Public License
  9  * @since       1.0
 10   */
 11 
 12 // Exit if accessed directly
 13 if ( ! defined( 'ABSPATH' ) ) exit;
 14 
 15 /**
 16  * Process Download
 17  *
 18  * Handles the file download process.
 19  *
 20  * @access      private
 21  * @since       1.0
 22  * @return      void
 23  */
 24 function edd_process_download() {
 25     $args = apply_filters( 'edd_process_download_args', array(
 26         'download' => ( isset( $_GET['download'] ) )     ? (int) $_GET['download']                          : '',
 27         'email'    => ( isset( $_GET['email'] ) )        ? rawurldecode( $_GET['email'] )                   : '',
 28         'expire'   => ( isset( $_GET['expire'] ) )       ? base64_decode( rawurldecode( $_GET['expire'] ) ) : '',
 29         'file_key' => ( isset( $_GET['file'] ) )         ? (int) $_GET['file']                              : '',
 30         'price_id' => ( isset( $_GET['price_id'] ) )     ? (int) $_GET['price_id']                          : false,
 31         'key'      => ( isset( $_GET['download_key'] ) ) ? $_GET['download_key']                            : ''
 32     ) );
 33 
 34     if( $args['download'] === '' || $args['email'] === '' || $args['file_key'] === '' )
 35         return false;
 36 
 37     extract( $args );
 38 
 39     $payment = edd_verify_download_link( $download, $key, $email, $expire, $file_key );
 40 
 41     // Defaulting this to true for now because the method below doesn't work well
 42     $has_access = apply_filters( 'edd_file_download_has_access', true, $payment, $args );
 43 
 44     //$has_access = ( edd_logged_in_only() && is_user_logged_in() ) || !edd_logged_in_only() ? true : false;
 45     if ( $payment && $has_access ) {
 46         do_action( 'edd_process_verified_download', $download, $email );
 47 
 48         // Payment has been verified, setup the download
 49         $download_files = edd_get_download_files( $download );
 50 
 51         $requested_file = apply_filters( 'edd_requested_file', $download_files[ $file_key ]['file'], $download_files, $file_key );
 52 
 53         $user_info = array();
 54         $user_info['email'] = $email;
 55         if ( is_user_logged_in() ) {
 56             global $user_ID;
 57             $user_data          = get_userdata( $user_ID );
 58             $user_info['id']    = $user_ID;
 59             $user_info['name']  = $user_data->display_name;
 60         }
 61 
 62         edd_record_download_in_log( $download, $file_key, $user_info, edd_get_ip(), $payment );
 63 
 64         $file_extension = edd_get_file_extension( $requested_file );
 65         $ctype          = edd_get_file_ctype( $file_extension );
 66 
 67         if ( !edd_is_func_disabled( 'set_time_limit' ) && !ini_get('safe_mode') ) {
 68             set_time_limit(0);
 69         }
 70         if ( function_exists( 'get_magic_quotes_runtime' ) && get_magic_quotes_runtime() ) {
 71             set_magic_quotes_runtime(0);
 72         }
 73 
 74         @session_write_close();
 75         if( function_exists( 'apache_setenv' ) ) @apache_setenv('no-gzip', 1);
 76         @ini_set( 'zlib.output_compression', 'Off' );
 77 
 78         nocache_headers();
 79         header("Robots: none");
 80         header("Content-Type: " . $ctype . "");
 81         header("Content-Description: File Transfer");
 82         header("Content-Disposition: attachment; filename=\"" . apply_filters( 'edd_requested_file_name', basename( $requested_file ) ) . "\";");
 83         header("Content-Transfer-Encoding: binary");
 84 
 85         $file_path = realpath( $requested_file );
 86 
 87         if ( strpos( $requested_file, 'http://' ) === false && strpos( $requested_file, 'https://' ) === false && strpos( $requested_file, 'ftp://' ) === false && file_exists( $file_path ) ) {
 88 
 89             /** This is an absolute path */
 90 
 91             edd_deliver_download( $file_path );
 92 
 93         } else if( strpos( $requested_file, WP_CONTENT_URL ) !== false ) {
 94 
 95             /** This is a local file given by URL */
 96             $upload_dir = wp_upload_dir();
 97 
 98             $file_path = str_replace( WP_CONTENT_URL, WP_CONTENT_DIR, $requested_file );
 99             $file_path = realpath( $file_path );
100 
101             if ( file_exists( $file_path ) ) {
102 
103                 edd_deliver_download( $file_path );
104 
105             } else {
106                 // Absolute path couldn't be discovered so send straight to the file URL
107                 header( "Location: " . $requested_file );
108             }
109         } else {
110             // This is a remote file
111             header( "Location: " . $requested_file );
112         }
113 
114         exit;
115     } else {
116         $error_message = __( 'You do not have permission to download this file', 'edd' );
117         wp_die( apply_filters( ' edd_deny_download_message', $error_message, __( 'Purchase Verification Failed', 'edd' ) ) );
118     }
119 
120     exit;
121 }
122 add_action( 'init', 'edd_process_download', 100 );
123 
124 
125 /**
126  * Deliver the download file
127  *
128  * If enabled, the file is symlinked to better support large file downloads
129  *
130  * @access   public
131  * @param    string    file
132  * @return   void
133  */
134 function edd_deliver_download( $file = '' ) {
135 
136     global $edd_options;
137 
138     $symlink = apply_filters( 'edd_symlink_file_downloads', isset( $edd_options['symlink_file_downloads'] ) );
139 
140     /*
141      * If symlinks are enabled, a link to the file will be created
142      * This symlink is used to hide the true location of the file, even when the file URL is revealed
143      * The symlink is deleted after it is used
144      */
145 
146     if( $symlink && function_exists( 'symlink' ) ) {
147 
148         // Generate a symbolic link
149         $ext       = edd_get_file_extension( $file );
150         $parts     = explode( '.', $file );
151         $name      = basename( $parts[0] );
152         $md5       = md5( $file );
153         $file_name = $name . '_' . substr( $md5, 0, -15 ) . '.' . $ext;
154         $path      = edd_get_symlink_dir() . '/' . $file_name;
155         $url       = edd_get_symlink_url() . '/' . $file_name;
156 
157         // Set a transient to ensure this symlink is not deleted before it can be used
158         set_transient( md5( $file_name ), '1', 30 );
159 
160         // Schedule deletion of the symlink
161         if ( ! wp_next_scheduled( 'edd_cleanup_file_symlinks' ) )
162             wp_schedule_single_event( time()+60, 'edd_cleanup_file_symlinks' );
163 
164         // Make sure the symlink doesn't already exist before we create it
165         if( ! file_exists( $path ) )
166             $link = symlink( $file, $path );
167         else
168             $link = true;
169 
170         if( $link ) {
171             // Send the browser to the file
172             header( 'Location: ' . $url );
173         } else {
174             @edd_readfile_chunked( $file );
175         }
176 
177     } else {
178 
179         // Read the file and deliver it in chunks
180         @edd_readfile_chunked( $file );
181 
182     }
183 
184 }
185 
186 
187 /**
188  * Get the file content type
189  *
190  * @access   public
191  * @param    string    file extension
192  * @return   string
193  */
194 function edd_get_file_ctype( $extension ) {
195     switch( $extension ):
196         case 'ac'       : $ctype    = "application/pkix-attr-cert"; break;
197         case 'adp'      : $ctype    = "audio/adpcm"; break;
198         case 'ai'       : $ctype    = "application/postscript"; break;
199         case 'aif'      : $ctype    = "audio/x-aiff"; break;
200         case 'aifc'     : $ctype    = "audio/x-aiff"; break;
201         case 'aiff'     : $ctype    = "audio/x-aiff"; break;
202         case 'air'      : $ctype    = "application/vnd.adobe.air-application-installer-package+zip"; break;
203         case 'apk'      : $ctype    = "application/vnd.android.package-archive"; break;
204         case 'asc'      : $ctype    = "application/pgp-signature"; break;
205         case 'atom'     : $ctype    = "application/atom+xml"; break;
206         case 'atomcat'  : $ctype    = "application/atomcat+xml"; break;
207         case 'atomsvc'  : $ctype    = "application/atomsvc+xml"; break;
208         case 'au'       : $ctype    = "audio/basic"; break;
209         case 'aw'       : $ctype    = "application/applixware"; break;
210         case 'avi'      : $ctype    = "video/x-msvideo"; break;
211         case 'bcpio'    : $ctype    = "application/x-bcpio"; break;
212         case 'bin'      : $ctype    = "application/octet-stream"; break;
213         case 'bmp'      : $ctype    = "image/bmp"; break;
214         case 'boz'      : $ctype    = "application/x-bzip2"; break;
215         case 'bpk'      : $ctype    = "application/octet-stream"; break;
216         case 'bz'       : $ctype    = "application/x-bzip"; break;
217         case 'bz2'      : $ctype    = "application/x-bzip2"; break;
218         case 'ccxml'    : $ctype    = "application/ccxml+xml"; break;
219         case 'cdmia'    : $ctype    = "application/cdmi-capability"; break;
220         case 'cdmic'    : $ctype    = "application/cdmi-container"; break;
221         case 'cdmid'    : $ctype    = "application/cdmi-domain"; break;
222         case 'cdmio'    : $ctype    = "application/cdmi-object"; break;
223         case 'cdmiq'    : $ctype    = "application/cdmi-queue"; break;
224         case 'cdf'      : $ctype    = "application/x-netcdf"; break;
225         case 'cer'      : $ctype    = "application/pkix-cert"; break;
226         case 'cgm'      : $ctype    = "image/cgm"; break;
227         case 'class'    : $ctype    = "application/octet-stream"; break;
228         case 'cpio'     : $ctype    = "application/x-cpio"; break;
229         case 'cpt'      : $ctype    = "application/mac-compactpro"; break;
230         case 'crl'      : $ctype    = "application/pkix-crl"; break;
231         case 'csh'      : $ctype    = "application/x-csh"; break;
232         case 'css'      : $ctype    = "text/css"; break;
233         case 'cu'       : $ctype    = "application/cu-seeme"; break;
234         case 'davmount' : $ctype    = "application/davmount+xml"; break;
235         case 'dbk'      : $ctype    = "application/docbook+xml"; break;
236         case 'dcr'      : $ctype    = "application/x-director"; break;
237         case 'deploy'   : $ctype    = "application/octet-stream"; break;
238         case 'dif'      : $ctype    = "video/x-dv"; break;
239         case 'dir'      : $ctype    = "application/x-director"; break;
240         case 'dist'     : $ctype    = "application/octet-stream"; break;
241         case 'distz'    : $ctype    = "application/octet-stream"; break;
242         case 'djv'      : $ctype    = "image/vnd.djvu"; break;
243         case 'djvu'     : $ctype    = "image/vnd.djvu"; break;
244         case 'dll'      : $ctype    = "application/octet-stream"; break;
245         case 'dmg'      : $ctype    = "application/octet-stream"; break;
246         case 'dms'      : $ctype    = "application/octet-stream"; break;
247         case 'doc'      : $ctype    = "application/msword"; break;
248         case 'docx'     : $ctype    = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"; break;
249         case 'dotx'     : $ctype    = "application/vnd.openxmlformats-officedocument.wordprocessingml.template"; break;
250         case 'dssc'     : $ctype    = "application/dssc+der"; break;
251         case 'dtd'      : $ctype    = "application/xml-dtd"; break;
252         case 'dump'     : $ctype    = "application/octet-stream"; break;
253         case 'dv'       : $ctype    = "video/x-dv"; break;
254         case 'dvi'      : $ctype    = "application/x-dvi"; break;
255         case 'dxr'      : $ctype    = "application/x-director"; break;
256         case 'ecma'     : $ctype    = "application/ecmascript"; break;
257         case 'elc'      : $ctype    = "application/octet-stream"; break;
258         case 'emma'     : $ctype    = "application/emma+xml"; break;
259         case 'eps'      : $ctype    = "application/postscript"; break;
260         case 'epub'     : $ctype    = "application/epub+zip"; break;
261         case 'etx'      : $ctype    = "text/x-setext"; break;
262         case 'exe'      : $ctype    = "application/octet-stream"; break;
263         case 'exi'      : $ctype    = "application/exi"; break;
264         case 'ez'       : $ctype    = "application/andrew-inset"; break;
265         case 'f4v'      : $ctype    = "video/x-f4v"; break;
266         case 'fli'      : $ctype    = "video/x-fli"; break;
267         case 'flv'      : $ctype    = "video/x-flv"; break;
268         case 'gif'      : $ctype    = "image/gif"; break;
269         case 'gml'      : $ctype    = "application/srgs"; break;
270         case 'gpx'      : $ctype    = "application/gml+xml"; break;
271         case 'gram'     : $ctype    = "application/gpx+xml"; break;
272         case 'grxml'    : $ctype    = "application/srgs+xml"; break;
273         case 'gtar'     : $ctype    = "application/x-gtar"; break;
274         case 'gxf'      : $ctype    = "application/gxf"; break;
275         case 'hdf'      : $ctype    = "application/x-hdf"; break;
276         case 'hqx'      : $ctype    = "application/mac-binhex40"; break;
277         case 'htm'      : $ctype    = "text/html"; break;
278         case 'html'     : $ctype    = "text/html"; break;
279         case 'ice'      : $ctype    = "x-conference/x-cooltalk"; break;
280         case 'ico'      : $ctype    = "image/x-icon"; break;
281         case 'ics'      : $ctype    = "text/calendar"; break;
282         case 'ief'      : $ctype    = "image/ief"; break;
283         case 'ifb'      : $ctype    = "text/calendar"; break;
284         case 'iges'     : $ctype    = "model/iges"; break;
285         case 'igs'      : $ctype    = "model/iges"; break;
286         case 'ink'      : $ctype    = "application/inkml+xml"; break;
287         case 'inkml'    : $ctype    = "application/inkml+xml"; break;
288         case 'ipfix'    : $ctype    = "application/ipfix"; break;
289         case 'jar'      : $ctype    = "application/java-archive"; break;
290         case 'jnlp'     : $ctype    = "application/x-java-jnlp-file"; break;
291         case 'jp2'      : $ctype    = "image/jp2"; break;
292         case 'jpe'      : $ctype    = "image/jpeg"; break;
293         case 'jpeg'     : $ctype    = "image/jpeg"; break;
294         case 'jpg'      : $ctype    = "image/jpeg"; break;
295         case 'js'       : $ctype    = "application/javascript"; break;
296         case 'json'     : $ctype    = "application/json"; break;
297         case 'jsonml'   : $ctype    = "application/jsonml+json"; break;
298         case 'kar'      : $ctype    = "audio/midi"; break;
299         case 'latex'    : $ctype    = "application/x-latex"; break;
300         case 'lha'      : $ctype  = "application/octet-stream"; break;
301         case 'lrf'      : $ctype  = "application/octet-stream"; break;
302         case 'lzh'      : $ctype  = "application/octet-stream"; break;
303         case 'lostxml'  : $ctype    = "application/lost+xml"; break;
304         case 'm3u'      : $ctype    = "audio/x-mpegurl"; break;
305         case 'm4a'      : $ctype    = "audio/mp4a-latm"; break;
306         case 'm4b'      : $ctype    = "audio/mp4a-latm"; break;
307         case 'm4p'      : $ctype    = "audio/mp4a-latm"; break;
308         case 'm4u'      : $ctype    = "video/vnd.mpegurl"; break;
309         case 'm4v'      : $ctype    = "video/x-m4v"; break;
310         case 'm21'      : $ctype    = "application/mp21"; break;
311         case 'ma'       : $ctype    = "application/mathematica"; break;
312         case 'mac'      : $ctype    = "image/x-macpaint"; break;
313         case 'mads'     : $ctype    = "application/mads+xml"; break;
314         case 'man'      : $ctype    = "application/x-troff-man"; break;
315         case 'mar'      : $ctype    = "application/octet-stream"; break;
316         case 'mathml'   : $ctype    = "application/mathml+xml"; break;
317         case 'mbox'     : $ctype    = "application/mbox"; break;
318         case 'me'       : $ctype    = "application/x-troff-me"; break;
319         case 'mesh'     : $ctype    = "model/mesh"; break;
320         case 'metalink' : $ctype    = "application/metalink+xml"; break;
321         case 'meta4'    : $ctype    = "application/metalink4+xml"; break;
322         case 'mets'     : $ctype    = "application/mets+xml"; break;
323         case 'mid'      : $ctype    = "audio/midi"; break;
324         case 'midi'     : $ctype    = "audio/midi"; break;
325         case 'mif'      : $ctype    = "application/vnd.mif"; break;
326         case 'mods'     : $ctype    = "application/mods+xml"; break;
327         case 'mov'      : $ctype    = "video/quicktime"; break;
328         case 'movie'    : $ctype    = "video/x-sgi-movie"; break;
329         case 'm1v'      : $ctype    = "video/mpeg"; break;
330         case 'm2v'      : $ctype    = "video/mpeg"; break;
331         case 'mp2'      : $ctype    = "audio/mpeg"; break;
332         case 'mp2a'     : $ctype    = "audio/mpeg"; break;
333         case 'mp21'     : $ctype    = "application/mp21"; break;
334         case 'mp3'      : $ctype    = "audio/mpeg"; break;
335         case 'mp3a'     : $ctype    = "audio/mpeg"; break;
336         case 'mp4'      : $ctype    = "video/mp4"; break;
337         case 'mp4s'     : $ctype    = "application/mp4"; break;
338         case 'mpe'      : $ctype    = "video/mpeg"; break;
339         case 'mpeg'     : $ctype    = "video/mpeg"; break;
340         case 'mpg'      : $ctype    = "video/mpeg"; break;
341         case 'mpg4'     : $ctype    = "video/mpeg"; break;
342         case 'mpga'     : $ctype    = "audio/mpeg"; break;
343         case 'mrc'      : $ctype    = "application/marc"; break;
344         case 'mrcx'     : $ctype    = "application/marcxml+xml"; break;
345         case 'ms'       : $ctype    = "application/x-troff-ms"; break;
346         case 'mscml'    : $ctype    = "application/mediaservercontrol+xml"; break;
347         case 'msh'      : $ctype    = "model/mesh"; break;
348         case 'mxf'      : $ctype    = "application/mxf"; break;
349         case 'mxu'      : $ctype    = "video/vnd.mpegurl"; break;
350         case 'nc'       : $ctype    = "application/x-netcdf"; break;
351         case 'oda'      : $ctype    = "application/oda"; break;
352         case 'oga'      : $ctype    = "application/ogg"; break;
353         case 'ogg'      : $ctype    = "application/ogg"; break;
354         case 'ogx'      : $ctype    = "application/ogg"; break;
355         case 'omdoc'    : $ctype    = "application/omdoc+xml"; break;
356         case 'onetoc'   : $ctype    = "application/onenote"; break;
357         case 'onetoc2'  : $ctype    = "application/onenote"; break;
358         case 'onetmp'   : $ctype    = "application/onenote"; break;
359         case 'onepkg'   : $ctype    = "application/onenote"; break;
360         case 'opf'      : $ctype    = "application/oebps-package+xml"; break;
361         case 'oxps'     : $ctype    = "application/oxps"; break;
362         case 'p7c'      : $ctype    = "application/pkcs7-mime"; break;
363         case 'p7m'      : $ctype    = "application/pkcs7-mime"; break;
364         case 'p7s'      : $ctype    = "application/pkcs7-signature"; break;
365         case 'p8'       : $ctype    = "application/pkcs8"; break;
366         case 'p10'      : $ctype    = "application/pkcs10"; break;
367         case 'pbm'      : $ctype    = "image/x-portable-bitmap"; break;
368         case 'pct'      : $ctype    = "image/pict"; break;
369         case 'pdb'      : $ctype    = "chemical/x-pdb"; break;
370         case 'pdf'      : $ctype    = "application/pdf"; break;
371         case 'pki'      : $ctype    = "application/pkixcmp"; break;
372         case 'pkipath'  : $ctype    = "application/pkix-pkipath"; break;
373         case 'pfr'      : $ctype    = "application/font-tdpfr"; break;
374         case 'pgm'      : $ctype    = "image/x-portable-graymap"; break;
375         case 'pgn'      : $ctype    = "application/x-chess-pgn"; break;
376         case 'pgp'      : $ctype    = "application/pgp-encrypted"; break;
377         case 'pic'      : $ctype    = "image/pict"; break;
378         case 'pict'     : $ctype    = "image/pict"; break;
379         case 'pkg'      : $ctype    = "application/octet-stream"; break;
380         case 'png'      : $ctype    = "image/png"; break;
381         case 'pnm'      : $ctype    = "image/x-portable-anymap"; break;
382         case 'pnt'      : $ctype    = "image/x-macpaint"; break;
383         case 'pntg'     : $ctype    = "image/x-macpaint"; break;
384         case 'pot'      : $ctype    = "application/vnd.ms-powerpoint"; break;
385         case 'potx'     : $ctype    = "application/vnd.openxmlformats-officedocument.presentationml.template"; break;
386         case 'ppm'      : $ctype    = "image/x-portable-pixmap"; break;
387         case 'pps'      : $ctype    = "application/vnd.ms-powerpoint"; break;
388         case 'ppsx'     : $ctype    = "application/vnd.openxmlformats-officedocument.presentationml.slideshow"; break;
389         case 'ppt'      : $ctype    = "application/vnd.ms-powerpoint"; break;
390         case 'pptx'     : $ctype    = "application/vnd.openxmlformats-officedocument.presentationml.presentation"; break;
391         case 'prf'      : $ctype    = "application/pics-rules"; break;
392         case 'ps'       : $ctype    = "application/postscript"; break;
393         case 'psd'      : $ctype    = "image/photoshop"; break;
394         case 'qt'       : $ctype    = "video/quicktime"; break;
395         case 'qti'      : $ctype    = "image/x-quicktime"; break;
396         case 'qtif'     : $ctype    = "image/x-quicktime"; break;
397         case 'ra'       : $ctype    = "audio/x-pn-realaudio"; break;
398         case 'ram'      : $ctype    = "audio/x-pn-realaudio"; break;
399         case 'ras'      : $ctype    = "image/x-cmu-raster"; break;
400         case 'rdf'      : $ctype    = "application/rdf+xml"; break;
401         case 'rgb'      : $ctype    = "image/x-rgb"; break;
402         case 'rm'       : $ctype    = "application/vnd.rn-realmedia"; break;
403         case 'rmi'      : $ctype    = "audio/midi"; break;
404         case 'roff'     : $ctype    = "application/x-troff"; break;
405         case 'rss'      : $ctype    = "application/rss+xml"; break;
406         case 'rtf'      : $ctype    = "text/rtf"; break;
407         case 'rtx'      : $ctype    = "text/richtext"; break;
408         case 'sgm'      : $ctype    = "text/sgml"; break;
409         case 'sgml'     : $ctype    = "text/sgml"; break;
410         case 'sh'       : $ctype    = "application/x-sh"; break;
411         case 'shar'     : $ctype    = "application/x-shar"; break;
412         case 'sig'      : $ctype    = "application/pgp-signature"; break;
413         case 'silo'     : $ctype    = "model/mesh"; break;
414         case 'sit'      : $ctype    = "application/x-stuffit"; break;
415         case 'skd'      : $ctype    = "application/x-koan"; break;
416         case 'skm'      : $ctype    = "application/x-koan"; break;
417         case 'skp'      : $ctype    = "application/x-koan"; break;
418         case 'skt'      : $ctype    = "application/x-koan"; break;
419         case 'sldx'     : $ctype    = "application/vnd.openxmlformats-officedocument.presentationml.slide"; break;
420         case 'smi'      : $ctype    = "application/smil"; break;
421         case 'smil'     : $ctype    = "application/smil"; break;
422         case 'snd'      : $ctype    = "audio/basic"; break;
423         case 'so'       : $ctype    = "application/octet-stream"; break;
424         case 'spl'      : $ctype    = "application/x-futuresplash"; break;
425         case 'spx'      : $ctype    = "audio/ogg"; break;
426         case 'src'      : $ctype    = "application/x-wais-source"; break;
427         case 'stk'      : $ctype    = "application/hyperstudio"; break;
428         case 'sv4cpio'  : $ctype    = "application/x-sv4cpio"; break;
429         case 'sv4crc'   : $ctype    = "application/x-sv4crc"; break;
430         case 'svg'      : $ctype    = "image/svg+xml"; break;
431         case 'swf'      : $ctype    = "application/x-shockwave-flash"; break;
432         case 't'        : $ctype    = "application/x-troff"; break;
433         case 'tar'      : $ctype    = "application/x-tar"; break;
434         case 'tcl'      : $ctype    = "application/x-tcl"; break;
435         case 'tex'      : $ctype    = "application/x-tex"; break;
436         case 'texi'     : $ctype    = "application/x-texinfo"; break;
437         case 'texinfo'  : $ctype    = "application/x-texinfo"; break;
438         case 'tif'      : $ctype    = "image/tiff"; break;
439         case 'tiff'     : $ctype    = "image/tiff"; break;
440         case 'torrent'  : $ctype    = "application/x-bittorrent"; break;
441         case 'tr'       : $ctype    = "application/x-troff"; break;
442         case 'tsv'      : $ctype    = "text/tab-separated-values"; break;
443         case 'txt'      : $ctype    = "text/plain"; break;
444         case 'ustar'    : $ctype    = "application/x-ustar"; break;
445         case 'vcd'      : $ctype    = "application/x-cdlink"; break;
446         case 'vrml'     : $ctype    = "model/vrml"; break;
447         case 'vsd'      : $ctype    = "application/vnd.visio"; break;
448         case 'vss'      : $ctype    = "application/vnd.visio"; break;
449         case 'vst'      : $ctype    = "application/vnd.visio"; break;
450         case 'vsw'      : $ctype    = "application/vnd.visio"; break;
451         case 'vxml'     : $ctype    = "application/voicexml+xml"; break;
452         case 'wav'      : $ctype    = "audio/x-wav"; break;
453         case 'wbmp'     : $ctype    = "image/vnd.wap.wbmp"; break;
454         case 'wbmxl'    : $ctype    = "application/vnd.wap.wbxml"; break;
455         case 'wm'       : $ctype    = "video/x-ms-wm"; break;
456         case 'wml'      : $ctype    = "text/vnd.wap.wml"; break;
457         case 'wmlc'     : $ctype    = "application/vnd.wap.wmlc"; break;
458         case 'wmls'     : $ctype    = "text/vnd.wap.wmlscript"; break;
459         case 'wmlsc'    : $ctype    = "application/vnd.wap.wmlscriptc"; break;
460         case 'wmv'      : $ctype    = "video/x-ms-wmv"; break;
461         case 'wmx'      : $ctype    = "video/x-ms-wmx"; break;
462         case 'wrl'      : $ctype    = "model/vrml"; break;
463         case 'xbm'      : $ctype    = "image/x-xbitmap"; break;
464         case 'xdssc'    : $ctype    = "application/dssc+xml"; break;
465         case 'xer'      : $ctype    = "application/patch-ops-error+xml"; break;
466         case 'xht'      : $ctype    = "application/xhtml+xml"; break;
467         case 'xhtml'    : $ctype    = "application/xhtml+xml"; break;
468         case 'xla'      : $ctype    = "application/vnd.ms-excel"; break;
469         case 'xlam'     : $ctype    = "application/vnd.ms-excel.addin.macroEnabled.12"; break;
470         case 'xlc'      : $ctype    = "application/vnd.ms-excel"; break;
471         case 'xlm'      : $ctype    = "application/vnd.ms-excel"; break;
472         case 'xls'      : $ctype    = "application/vnd.ms-excel"; break;
473         case 'xlsx'     : $ctype    = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"; break;
474         case 'xlsb'     : $ctype    = "application/vnd.ms-excel.sheet.binary.macroEnabled.12"; break;
475         case 'xlt'      : $ctype    = "application/vnd.ms-excel"; break;
476         case 'xltx'     : $ctype    = "application/vnd.openxmlformats-officedocument.spreadsheetml.template"; break;
477         case 'xlw'      : $ctype    = "application/vnd.ms-excel"; break;
478         case 'xml'      : $ctype    = "application/xml"; break;
479         case 'xpm'      : $ctype    = "image/x-xpixmap"; break;
480         case 'xsl'      : $ctype    = "application/xml"; break;
481         case 'xslt'     : $ctype    = "application/xslt+xml"; break;
482         case 'xul'      : $ctype    = "application/vnd.mozilla.xul+xml"; break;
483         case 'xwd'      : $ctype    = "image/x-xwindowdump"; break;
484         case 'xyz'      : $ctype    = "chemical/x-xyz"; break;
485         case 'zip'      : $ctype    = "application/zip"; break;
486         default         : $ctype    = "application/force-download";
487     endswitch;
488 
489     return apply_filters( 'edd_file_ctype', $ctype );
490 }
491 
492 /**
493  * Reads file in chunks so big downloads are possible without changing PHP.INI
494  * See http://codeigniter.com/wiki/Download_helper_for_large_files/
495  *
496  * @access   public
497  * @param    string  $file      The file
498  * @param    boolean $retbytes  Return the bytes of file
499  * @return   bool|string - If string, $status || $cnt
500  */
501 function edd_readfile_chunked( $file, $retbytes = TRUE ) {
502 
503     $chunksize = 1 * (1024 * 1024);
504     $buffer    = '';
505     $cnt       = 0;
506     $handle    = fopen( $file, 'r' );
507 
508     if( $size = @filesize( $requested_file ) ) header("Content-Length: " . $size );
509 
510     if ( $handle === FALSE ) return FALSE;
511 
512     while ( ! feof( $handle ) ) :
513        $buffer = fread( $handle, $chunksize );
514        echo $buffer;
515        ob_flush();
516        flush();
517 
518        if ( $retbytes ) $cnt += strlen( $buffer );
519     endwhile;
520 
521     $status = fclose( $handle );
522 
523     if ( $retbytes AND $status ) return $cnt;
524 
525     return $status;
526 }
Easy Digital Downloads API documentation generated by ApiGen 2.8.0