PriMoThemes — now s2Member® (official notice)

This is now a very OLD forum system. It's in READ-ONLY mode.
All community interaction now occurs at WP Sharks™. See: new forums @ WP Sharks™

Using X-Sendfile for downloads

s2Member Plugin. A Membership plugin for WordPress®.

Using X-Sendfile for downloads

Postby fx_keith » December 5th, 2011, 3:19 pm

Hey, I'm trying to bypass the self-hosted file downloads to pass it off to X-Sendfile on my server. I've had it working in older versions of s2member by hacking it into the plugin, but I obviously want to do this through an action hook instead.

Looking at classes/files-in.inc.php it looks like files are downloaded towards the end of 'c_ws_plugin__s2member_files_in::check_file_download_access', but I'm not seeing something I can plug into without clobbering all the file checking.

Ideally, I'd like to replace all the file headers in line #331
Code: Select all
else /* Else, ``if ($serving)`` , use local storage option (default).*/
with an X-Sendfile header like:
Code: Select all
header("X-Sendfile: $file_path");


Any suggestions on accomplishing that?
User avatar
fx_keith
Experienced User
Experienced User
 
Posts: 6
Joined: November 21, 2011

Re: Using X-Sendfile for downloads

Postby Jason Caldwell » December 7th, 2011, 2:58 am

I would suggest using this Hook:
ws_plugin__s2member_during_file_download_access
viewtopic.php?f=40&t=13012&src_doc_v=111206#src_doc_line_274

Something like this perhaps.
Code: Select all
<?php
add_action 
("ws_plugin__s2member_during_file_download_access", "my_s2_file_server");
function my_s2_file_server ($vars = array ())
    {
        if ($vars["serving"])
            {
                // Send file headers, and exit script execution.
                print_r($vars); // For debugging.
                exit ();
            }
    }
?>
~ Jason Caldwell / Lead Developer
& Zeitgeist Movie Advocate: http://www.zeitgeistmovie.com/

Is the s2Member plugin working for you? Please rate s2Member at WordPress.org.
You'll need a WordPress.org account ( comes in handy ). Then rate s2Member here Image
.
User avatar
Jason Caldwell
Lead Developer
Lead Developer
 
Posts: 4045
Joined: May 3, 2010
Location: Georgia / USA

Re: Using X-Sendfile for downloads

Postby fx_keith » December 7th, 2011, 3:33 am

Excellent. Thanks again Jason.
Note to anyone else doing this, the filepath in this example would simply be $vars['file'];
User avatar
fx_keith
Experienced User
Experienced User
 
Posts: 6
Joined: November 21, 2011

Re: Using X-Sendfile for downloads

Postby Raam Dev » December 7th, 2011, 9:31 pm

Thanks for the tip, fx_keith! :)
Raam Dev || Wherever you are, be there. || Please rate s2Member!
User avatar
Raam Dev
Developer
Developer
 
Posts: 810
Joined: October 26, 2011

Re: Using X-Sendfile for downloads

Postby fx_keith » December 7th, 2011, 9:40 pm

FYI - the headers are super simple. Mine look something like this.
Code: Select all
$file = $vars['file'];
$filename = basename($file);
$length = filesize($file);
header("USING_XSENDFILE: TRUE"); //for testing
header("X-Sendfile: $file");
header("Content-Length: $length");
header("Content-Type: application/octet-stream");
header("Content-Disposition: attachment; filename=\"$filename\"");
User avatar
fx_keith
Experienced User
Experienced User
 
Posts: 6
Joined: November 21, 2011

Re: Using X-Sendfile for downloads

Postby Cristián Lávaque » December 9th, 2011, 2:34 am

Thanks for the info! :)
Cristián Lávaque http://s2member.net
Is s2Member working for you? Please rate it Image at WordPress.org. Thanks! :)
User avatar
Cristián Lávaque
Developer
Developer
 
Posts: 6836
Joined: December 22, 2010


Return to s2Member Plugin

Who is online

Users browsing this forum: Exabot [Bot] and 1 guest

cron