wpsc_alter_download_action

Located in: ajax.function.php

Functions that call this hook: wpsc_download_file()
Arguments Accepted: $file_id
Version Introduced: 3.8

Description: This hook is triggered just before the file is output to the browser for downloading (either via the email or via the transaction_results page). you can use this action to output the file download via a different method.

Code in context:
[php firstline=”1031″ highlight=”1050″]
$wpdb->update( WPSC_TABLE_DOWNLOAD_STATUS, array(
‘downloads’ => $download_count
), array( ‘id’ => $download_data[‘id’] ) );
$cart_contents = $wpdb->get_results( "SELECT `" . WPSC_TABLE_CART_CONTENTS . "`.*, $wpdb->posts.`guid` FROM `" . WPSC_TABLE_CART_CONTENTS . "` LEFT JOIN $wpdb->posts ON `" . WPSC_TABLE_CART_CONTENTS . "`.`prodid`= $wpdb->posts.`post_parent` WHERE $wpdb->posts.`post_type` = ‘wpsc-product-file’ AND `purchaseid` =" . $download_data[‘purchid’], ARRAY_A );
$dl = 0;

foreach ( $cart_contents as $cart_content ) {
if ( $cart_content[‘guid’] == 1 ) {
$dl++;
}
}
if ( count( $cart_contents ) == $dl ) {
$wpdb->update( WPSC_TABLE_PURCHASE_LOGS, array(
‘processed’ => ‘4’
), array( ‘id’ => $download_data[‘purchid’] ) );
}

do_action( ‘wpsc_alter_download_action’, $file_id );

$file_path = WPSC_FILE_DIR . basename( $file_data->post_title );
$file_name = basename( $file_data->post_title );

if ( is_file( $file_path ) ) {
if( !ini_get(‘safe_mode’) ) set_time_limit(0);
header( ‘Content-Type: ‘ . $file_data->post_mime_type );
header( ‘Content-Length: ‘ . filesize( $file_path ) );
header( ‘Content-Transfer-Encoding: binary’ );
header( ‘Content-Disposition: attachment; filename="’ . stripslashes( $file_name ) . ‘"’ );
if ( isset( $_SERVER["HTTPS"] ) && ($_SERVER["HTTPS"] != ”) ) {
/*
There is a bug in how IE handles downloads from servers using HTTPS, this is part of the fix, you may also need:
session_cache_limiter(‘public’);
session_cache_expire(30);
At the start of your index.php file or before the session is started
*/
header( "Pragma: public" );
header( "Expires: 0" );
header( "Cache-Control: must-revalidate, post-check=0, pre-check=0" );
header( "Cache-Control: public" );
} else {
header( ‘Cache-Control: must-revalidate, post-check=0, pre-check=0’ );
}
header( "Pragma: public" );
header( "Expires: 0" );

// destroy the session to allow the file to be downloaded on some buggy browsers and webservers
session_destroy();
wpsc_readfile_chunked( $file_path );
exit();
}else{
wp_die(__(‘Sorry something has gone wrong with your download!’, ‘wpsc’));
}
} else {
exit( _e( ‘This download is no longer valid, Please contact the site administrator for more information.’, ‘wpsc’ ) );
}
}
}

add_action( ‘init’, ‘wpsc_download_file’ );

[/php]