Resource Files outside the public directory not loading

  • Several Perch versions ago in 2.8 something it was suggested that the resources be put outside the public directory in members only section. So we did that but now they will not load and we do not want to have to load all those files in again. Is there a way to move the files to the public html directory and have them work by changing a line of code. There are thousands of these files. https://www.websitename.org/me…=/dachstaedter-george.pdf is one of the links. Is there a way to manually edit the link to point to a resource file in the public directory without loading all the files in again.

  • Here is the diagnostics for the site where the secure folder outside of the public html is not working

    • Perch: 3.1.4, PHP: 5.6.40, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 76b08b24596e12d4553bd41fc93cccd5bac2fe7a $, with PDO
    • Server OS: Linux, fpm-fcgi
    • Installed apps: content (3.1.4), assets (3.1.4), categories (3.1.4), perch_members (1.3), perch_members (1.6.4)
    • App runtimes: <?php $apps_list = [ 'perch_members', ]; ?>
    • PERCH_LOGINPATH: /pggs2.8.6_update
    • PERCH_PATH: /home/palamger/public_html/pggs2.8.6_update
    • PERCH_CORE: /home/palamger/public_html/pggs2.8.6_update/core
    • PERCH_RESFILEPATH: /home/palamger/public_html/pggs2.8.6_update/secure
    • Image manipulation: GD
    • PHP limits: Max upload 128M, Max POST 128M, Memory: 1024M, Total max file upload: 128M
    • F1: 3b606135b33e6a102526838f4152a807
    • Resource folder writeable: Yes
    • HTTP_HOST: http://www.HOST.ORG

    ~~~

    <perch:before>

    <table class="responsive" style="border:1px solid #000;width="75%"><tr style="background-color:#fff;font-color:#232376;font-weight:bold;">

    <th style="border-right:1px solid #232376;font-color:#232376;">LAST NAME</th><th style="border-right:1px solid #232376;font-color:#232376;">FIRST NAME</th><th style="border-right:1px solid #23237;font-color:#232376;">COMMENTS</th></tr>

    </perch:before>

    <tr>

    <td style="border:1px solid #000;">

    <a href="<perch:content id="file" type="file" label="File" order="2" accept="pdf doc" bucket="secure" />">

    <perch:content type="text" id="desc" label="lastname" order="1" required="true" title="true" />

    </a>

    </td>

    <td style="border:1px solid #000;"><perch:content id="firstname" type="text" label="First Name"/></td>

    <td style="border:1px solid #000;"><perch:content id="comments" type="textblock" label="Comments"/></td>

    </tr>

    <perch:after>

    </table>

    <perch:if exists="paging">

    <div class="paging">

    Page <perch:content id="current_page" type="hidden" /> of <perch:content id="number_of_pages" type="hidden" />

    <perch:if exists="not_first_page">

    <a href="<perch:content id="prev_url" type="hidden" encode="false" />">Previous</a>

    </perch:if>

    <perch:content id="page_links" encode="false" />

    <perch:if exists="not_last_page">

    <a href="<perch:content id="next_url" type="hidden" encode="false" />">Next</a>

    </perch:if>

    </div>

    </perch:if>

    </perch:after>

    ~~~

    buckets.php

    ~~~~

    <?php

    return array(

    'secure' => array(

    'web_path' => '/members/download.php?file=',

    'file_path' => '/home/palamger/secure',

    ),

    );

    ?>

    ~~~

    config file redacted

    ~~~


    <?php

    define('PERCH_LICENSE_KEY', '#here');


    define("PERCH_DB_USERNAME", 'u1');

    define("PERCH_DB_PASSWORD", 'pass');

    define("PERCH_DB_SERVER", "localhost");

    define("PERCH_DB_DATABASE", "dbname");

    define("PERCH_DB_PREFIX", "perch2_");


    define('PERCH_TZ', 'UTC');


    define('PERCH_EMAIL_FROM', 'webmaster@s.org');

    define('PERCH_EMAIL_FROM_NAME', 'Name of Organization');

    define('PERCH_EMAIL_METHOD', 'pop');

    define('PERCH_EMAIL_HOST', 'smtpout.secureserver.net');

    define('PERCH_EMAIL_AUTH', true);

    define('PERCH_EMAIL_SECURE', 'ssl');

    define('PERCH_EMAIL_PORT', 465);

    define('PERCH_EMAIL_USERNAME', 'username');

    define('PERCH_EMAIL_PASSWORD', 'pa

    ~~~~

    config


    define('PERCH_LOGINPATH', '/pggs2.8.6_update');

    define('PERCH_PATH', str_replace(DIRECTORY_SEPARATOR.'config', '', __DIR__));

    define('PERCH_CORE', PERCH_PATH.DIRECTORY_SEPARATOR.'core');

    // define('PERCH_RESFILEPATH', '/home/palamger/public_html/members/resources2015');

    //define('PERCH_RESPATH', '/members/resources2015');


    define('PERCH_RESFILEPATH', PERCH_PATH . DIRECTORY_SEPARATOR . 'secure');

    define('PERCH_RESPATH', PERCH_LOGINPATH . '/secure');


    define('PERCH_HTML5', true);

    ~~~

    finally the download.php file

    ~~~

    <?php

    include('../pggs2.8.6_update/runtime.php');


    // config

    $bucket_name = 'secure';

    $url_param = 'file';



    // By default, deny downloads unless we've proved the member is allowed this file.

    $allow_download = false;



    // Check a member is logged in

    if (perch_member_logged_in()) {

    $allow_download = false;

    }


    /*

    Alternatively, you could check for a specific tag, e.g.

    */

    if (perch_member_has_tag('member')) {

    $allow_download = true;

    }





    // Deliver the file.

    if ($allow_download) {

    perch_members_secure_download(perch_get($url_param), $bucket_name, false);

    }


    exit;

    _____


    These ARE THE FILES WHERE IS THE PROBLEM?

  • You are only allowing downloads for logged in members that have the tag member. Is this the behaviour you're after? If so, you can remove the first if statement:

    PHP
    1. /*
    2. if (perch_member_logged_in()) {
    3. $allow_download = false;
    4. }
    5. */
    6. if (perch_member_has_tag('member')) {
    7. $allow_download = true;
    8. }



    Have you tested this with a logged-in member that has the tag member?

  • It is commented out so that shouldn't be effecting anything should it? But it is still not working. Are you saying the coding is correct? Maybe because I can't log out - that started not working also.

  • Try to isolate the issue. Test the file delivery with no member restriction (in a development/staging environment):


    PHP
    1. <?php
    2. include('../pggs2.8.6_update/runtime.php');
    3. $bucket_name = 'secure';
    4. $url_param = 'file';
    5. perch_members_secure_download(perch_get($url_param), $bucket_name, false);
    6. exit;


    The above should serve the file to any visitor.

  • Ok. Now that you have confirmed that the file delivery functionality is not the issue you can focus on the logic that enables the download.


    You had an if statement that checks whether a logged-in member has the tag member:


    Code
    1.  if (perch_member_has_tag('member')) {
    2. $allow_download = true;
    3. }


    So I assume you have members that have the tag member. Did you test while logged-in as a member that has the tag member?