简体   繁体   中英

Can someone please point out why my require_once() function can't find the path? php

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?

试试这个require_once('./private/initialize.php');

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM