3

I can't seem to find the answer and I have asked everyone I know.

On my local server my code worked perfectly fine. When I uploaded it to a server, the require_once(); function stopped working. My file system is very simple. In the main website folder I have: index.php, private (folder) and public(folder).

When I run the website I get this error

"Warning: require_once(private/initialize.php): failed to open stream: No such file or directory in /home2/inbounf6/public_html/zampi/index.php on line 6"

This is what is on line 6: require_once('private/initialize.php');

I have tried every version of the file path I can think of and nothing works.

When I move things around and I put it in the same folder, it works fine. So I think the issue is going down a folder or in other words it isn't accessing the private folder.

Both the permissions for the private folder and initialize.php are 7 5 5.

Any body know what is going on?

VinothRaja
  • 1,405
  • 10
  • 21
Keet
  • 39
  • 3
  • what about permissions? who runs the server, wsho owns the private folder, what permissions does it have? – Juan Oct 09 '18 at 04:56
  • Have you tried the solutions in this post? https://stackoverflow.com/questions/5116421/require-once-failed-to-open-stream-no-such-file-or-directory – ultrajohn Oct 09 '18 at 04:56
  • Possible duplicate of [require\_once :failed to open stream: no such file or directory](https://stackoverflow.com/questions/5116421/require-once-failed-to-open-stream-no-such-file-or-directory) – ultrajohn Oct 09 '18 at 04:57
  • You should use realpath(), and use dirname(__FILE__) to get your current directory: require_once(realpath(dirname(__FILE__) . '/../includes/dbconn.inc')); – Hetal Oct 09 '18 at 05:09
  • Try permission 777 because some of system not allow access to web with 755 – Nishit Manjarawala Oct 09 '18 at 05:16
  • check for www-data file permission for that private folder and file – Sooraj N Raju Oct 09 '18 at 06:10
  • @Hetal After I added that piece of code I got this error: Warning: require_once(/home2/inbounf6/public_html/zampi): failed to open stream: No such file or directory in /home2/inbounf6/public_html/zampi/index.php on line 2 – Keet Oct 09 '18 at 15:30
  • @NishitManjarawala Even after I updated the permissions to 777 nothing changed. Any other guesses? – Keet Oct 09 '18 at 15:32
  • @SoorajNRaju Could you explain how to do that? I am using Bluehost. It is a pretty normal linux host. – Keet Oct 09 '18 at 15:37

2 Answers2

0

Try this require_once('./private/initialize.php');

Dave
  • 3,073
  • 7
  • 20
  • 33
Skinna
  • 1
0

Use magic constant __DIR__:

require_once(__DIR__ . '/private/initialize.php'));

__DIR__ The directory of the file. If used inside an include, the directory of the included file is returned. This is equivalent to dirname(FILE). This directory name does not have a trailing slash unless it is the root directory.

Madhur Bhaiya
  • 28,155
  • 10
  • 49
  • 57