-1

I need to include a library, which I have stored directly in public_html.

I can't seem to include it with this in the file abc.php which is also stored directly under public_html...

 include_once '../sdk-core-php-master';

The error keeps telling me

 PHP Warning:  include_once(../sdk-core-php-master): failed to open stream: No such file or directory in /home/abc/domains/abc.com/public_html/abc.php 

I tried many variations like adding more ../ in front but to no luck. Get same error. Please help. Thanks!

minjiera
  • 336
  • 3
  • 16

4 Answers4

1

ATT:

you don't add the extension:

include_once(../sdk-core-php-master):

it should be: include_once('../sdk-core-php-master.php'):

you can use magic constant to handle it. see reference here: PHP Magic Constant

to see your directory, just echo as follows:

dirname(__FILE__);

so, write your including file, as follows:

include_once(dirname(__FILE__) . '/sdk-core-php-master');

If it still not working, you can add commentary lines, as follows (and this should work):

e.g.

<?php
##########-------------start:anticrash--------------##########
##############################################################
##########--------------end:anticrash---------------##########
 include_once '../sdk-core-php-master';
//.............
//other codes
?>
don magug
  • 332
  • 1
  • 12
  • 1
    `__DIR__` is a shorter equivalent – DarkBee Mar 01 '15 at 22:01
  • 1
    i have the same issue with this, but I really like using anticrash and it works successfully. is there anything a bug so that commentary in php could be the solution? – Joe Kdw Mar 01 '15 at 22:03
0

If I'm understanding your question right, you're trying to use a php library, which means you have to add the .php extension like:

include_once '../sdk-core-php-master.php';

Edit: If you're trying to include multiple files from one folder, take a look at this question: How to include() all PHP files from a directory?

Community
  • 1
  • 1
Koeno
  • 1,493
  • 2
  • 16
  • 30
0

It is better to use the address of files from the root drive. In variable $_SERVER['DOCUMENT_ROOT'] holds the address of the site root. Added to this address of files from the root of the site. For example:

include_once($_SERVER['DOCUMENT_ROOT'] . "/some-folder/sdk-core-php-master.php");

Vladislav
  • 81
  • 9
0

Thanks all for your answer. I fixed it eventually. Apparently, my included path was set incorrectly. So I reset it to

set_include_path('http://www.example.com/');

and then include every file in the folder...it works now.

foreach (glob('sdk-core-php-master/*') as $filename)
{
    include_once $filename;
}
minjiera
  • 336
  • 3
  • 16