简体   繁体   English

php无法打开流:没有这样的文件或目录

[英]php failed to open stream: No such file or directory

I have 3 files: database.php, intialize.php and config.php. 我有3个文件:database.php,intialize.php和config.php。 The 3 files are located under a folder named: 这3个文件位于以下文件夹中:

usr/loca/nginx/html/phpcode/php/999_projects/test/include/

database.php database.php

<?php

echo "before";
require_once('initialize.php');
echo "after";

echo LIB_PATH;
?>

initialize.php initialize.php

<?php

// DIRECTORY_SEPARATOR is a PHP pre-defined constant
// (\ for Windows, / for Unix)
defined('DS') ? null : define('DS', DIRECTORY_SEPARATOR);

defined('SITE_ROOT') ? null : 
    define('SITE_ROOT', $_SERVER["DOCUMENT_ROOT"].DS.'phpcode'.DS.'php'.DS.'999_projects'.DS.'test');

defined('LIB_PATH') ? null : define('LIB_PATH', SITE_ROOT.DS.'includes');

// load config file first
require_once(LIB_PATH.DS.'config.php');
?>

config.php config.php

<?php

// Database Constants

defined('MYSQL_DSN') ? null : define("MYSQL_DSN", "mysql:host=localhost;dbname=talkback");
defined('DB_USER')   ? null : define("DB_USER", "user");
defined('DB_PASS')   ? null : define("DB_PASS", "pass");

?>

Once I run database.php, I get the following: 一旦运行database.php,我将得到以下信息:

Warning: require_once(/usr/local/nginx/html/phpcode/php/999_projects/test/includes/config.php): failed to open stream: No such file or directory in /usr/local/nginx/html/phpcode/php/999_projects/test/include/initialize.php on line 16 警告:require_once(/usr/local/nginx/html/phpcode/php/999_projects/test/includes/config.php):无法打开流:/ usr / local / nginx / html / phpcode /中没有这样的文件或目录第16行的php / 999_projects / test / include / initialize.php

AND

Fatal error: require_once(): Failed opening required '/usr/local/nginx/html/phpcode/php/999_projects/talkback/includes/config.php' (include_path='.:/usr/share/php:/usr/share/pear') in /usr/local/nginx/html/phpcode/php/999_projects/talkback/include/initialize.php on line 16 致命错误:require_once():无法打开所需的'/usr/local/nginx/html/phpcode/php/999_projects/talkback/includes/config.php'(include_path ='。:/ usr / share / php:/ usr /第16行的/usr/local/nginx/html/phpcode/php/999_projects/talkback/include/initialize.php中的share / pear')

The 3 files have the proper permissions and also the web server has permission to access these files. 这3个文件具有适当的权限,并且Web服务器也具有访问这些文件的权限。

I have tried for the past couple of hours (!) to fix it, however, I can`t find what am I missing. 我已经尝试了过去几个小时(!)来修复它,但是,我找不到我缺少的东西。

Can someone please assist? 有人可以帮忙吗?

Thanks, 谢谢,

Qwerty Qwerty

I think it is because you have written this: 我认为这是因为您已编写以下代码:

define('LIB_PATH', SITE_ROOT.DS.'includes');

... whereas in fact you meant to write this, without an 's': ...而实际上您的意思是写这个,不带's':

define('LIB_PATH', SITE_ROOT.DS.'include');

I'm inferring this from the last bit of each of those errors - it seems the file from which these other two are being included lives in the 'include' rather than the 'includes' directory? 我是从每个错误的最后一位推断出来的-似乎其他两个错误所在的文件都位于“ include”目录而不是“ includes”目录中?

/usr/local/nginx/html/phpcode/php/999_projects/talkback/include/initialize.php on line 16

Well the locations you said don't match the location in the errors. 您说的位置与错误中的位置不符。

You said they were all located under: 您说他们都位于以下位置:

/usr/loca/nginx/html/phpcode/php/999_projects/test/include/

but the errors say: 但是错误说:

/usr/local/nginx/html/phpcode/php/999_projects/talkback/include/

one says 'talkback', one says 'test'. 一个说“对讲”,一个说“测试”。 And one also says 'include', while the other says 'includes' But, if you positive they're under the same folder, and or those are the correct locations, more than likely the web-server does not have read access to that file. 一个也说“ include”,另一个说“ includes”。但是,如果您确定它们位于同一文件夹下,或者这些位置正确,则网络服务器很可能没有对该目录的读取权限文件。

You can check if the file path is right but going into a terminal, and typing: 您可以检查文件路径是否正确,但是要进入终端,然后输入:

cat /usr/local/nginx/html/phpcode/php/999_projects/talkback/includes/config.php

if that works then the path is right, and it will be a permissions issue, which you can check using ls -l, and changing with the chmod command (usually chmod 755 works fine). 如果可行,则路径正确,这将是一个权限问题,您可以使用ls -l进行检查,并使用chmod命令进行更改(通常chmod 755可以正常使用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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