• Resolved pxlsse

    (@pxlsse)


    I have an issue with require a file in a directory. E.g I want to require a file in the directory /vendor/autoload.php

    require_once __DIR__ . '/vendor/autoload.php';
    use ipinfo\ipinfo\IPinfo;
    $access_token = '3278463abc';
    $settings = ['cache_disabled' => true];
    $client = new IPinfo($access_token);
    $ip_address = '000.000.00.00.0';
    $details = $client->getDetails($ip_address);
    
    $details->loc;

    I get the error:
    Failed opening required /home2/malesbarbercom/public_html/wp-content/plugins/insert-headers-and-footers/includes/vendor/autoload.php (include_path=.:/opt/alt/php81/usr/share/pear:/opt/alt/php81/usr/share/php:/usr/share/pear:/usr/share/php)

    Why does it add “/wp-content/plugins/insert-headers-and-footers/includes/” in the directory output? And what is the solution?

Viewing 3 replies - 1 through 3 (of 3 total)
  • Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @pxlsse,

    That’s happening because you are trying to use a relative path and the script is looking for the vendor/autoload.php file in the directory of where the snippet is being executed, which is inside the WPCode plugin.

    You need to use an absolute path if you uploaded the vendor folder to your website. Are you using composer and uploaded a vendor folder to your website? If not, that will not work.

    Thread Starter pxlsse

    (@pxlsse)

    Hi Mircea and thanks for a fast reply!
    I installed the package through cpanel PHP Pear.
    I tried to change the path in the code to the full ‘absolute’ path (which is: home2/*domain*/public_html/vendor/autoload.php), but same issue…

    Plugin Author Mircea Sandu

    (@gripgrip)

    Hi @pxlsse,

    That’s likely not the absolute path, you can try using the ABSPATH constant but in either case you should first check via FTP that the file you are trying to include is actually available in the public_html folder.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘require_once __DIR__’ is closed to new replies.