php 致命错误:require_once():需要打开失败
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21133000/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Fatal error: require_once(): Failed opening required
提问by Massimo Variolo
I'm trying to run my online site on my local machine. I stumbled upon a problem.
我正在尝试在本地机器上运行我的在线站点。我偶然发现了一个问题。
This is my htaccess
这是我的 htaccess
AddDefaultCharset UTF-8
Options -Indexes
#php_value include_path .:/home/sites/www.example.it/example.it/htdocs/conf/
php_value include_path .:/XAMPP/htdocs/conf/
php_value display_errors on
php_value upload_max_filesize 20M
php_value post_max_size 50M
php_flag magic_quotes_gpc Off
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
#RewriteBase /
#RewriteCond %{HTTP_HOST} ^example.it [NC]
#RewriteRule ^(.*)$ http://www.example.it/ [L,R=301]
</IfModule>
<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteCond %{REQUEST_URI} /common.*
RewriteRule ^common/(.*) resources/media/common/
RewriteCond %{REQUEST_URI} /upload/img.*
RewriteRule ^upload/img/(.*)$ wapp/ir.php?path=&%{QUERY_STRING}
RewriteCond %{REQUEST_URI} /upload.*
RewriteRule ^upload/(.*) resources/upload/
RewriteCond %{REQUEST_URI} !/google.*
RewriteCond %{REQUEST_URI} !/common.*
RewriteCond %{REQUEST_URI} !/upload.*
RewriteCond %{REQUEST_URI} !/upload/img/.*
RewriteCond %{REQUEST_URI} !/wapp/ir.php
RewriteRule ^(.*)$ wapp/index.php?url=
</IfModule>
The error I receive:
我收到的错误:
Warning:require_once(conf.inc.php): failed to open stream: No such file or directory in C:\XAMPP\htdocs\wapp\index.php on line 2
警告:require_once(conf.inc.php): failed to open stream: No such file or directory in C:\XAMPP\htdocs\wapp\index.php on line 2
Fatal error:require_once(): Failed opening required 'conf.inc.php' (include_path='.:/XAMPP/htdocs/conf/') in C:\XAMPP\htdocs\wapp\index.php on line 2
致命错误:require_once(): Failed opening required 'conf.inc.php' (include_path='.:/XAMPP/htdocs/conf/') in C:\XAMPP\htdocs\wapp\index.php on line 2
How can I solve it? Maybe it deals with the privileges of the xampp user ...
我该如何解决?也许它涉及 xampp 用户的权限......
edit:
编辑:
getcwd() gives meC:\XAMPP\htdocs\wapp
getcwd() 给我C:\XAMPP\htdocs\wapp
conf.inc.php is located in:C:\XAMPP\htdocs\conf\
conf.inc.php 位于:C:\XAMPP\htdocs\conf\
the require in index.php:require_once("conf.inc.php");
index.php 中的 require:require_once("conf.inc.php");
回答by Soundz
try chdir(dirname(__FILE__))this sets the relative path to the path of the file.
So C:\XAMPP\htdocs\wapp\becomes your "root directory" and therefore config.inc.phpis the same as C:\XAMPP\htdocs\wapp\config.inc.php. If this still doesn't to the trick check your file paths
试试chdir(dirname(__FILE__))这个设置文件路径的相对路径。SoC:\XAMPP\htdocs\wapp\成为您的“根目录”,因此config.inc.php与C:\XAMPP\htdocs\wapp\config.inc.php. 如果这仍然不能解决问题,请检查您的文件路径
Edit:
编辑:
You have to traverse there. Check the relative root of the project (getcwd()). I assume its C:\XAMPP\htdocs\wapp\you have to change your require to this:
你必须穿越那里。检查项目的相对根目录 ( getcwd())。我认为C:\XAMPP\htdocs\wapp\您必须将您的要求更改为:
require_once ('../conf/conf.inc.php')the ..make you go up one directory
require_once ('../conf/conf.inc.php')在..化妆你去了一个目录
OK just do this:
好的,只需这样做:
require_once("../conf/conf.inc.php");
require_once("../conf/conf.inc.php");

