2013-11-01 21:13
采纳率: 100%
浏览 67

要求和包含无法查找和打开文件PHP 5.5.5

Running PHP 5.5.5 FPM/FastCGI on CentOS 6.4 x64 with Nginx.

require_once(dirname(__FILE__) . '/adminsetting.php') or die();

returns the following error:

PHP Fatal error:  require_once(): Failed opening required '1'
(include_path='.:/usr/share/pear:/usr/share/php') in
/home/vincek/public_html/plg/index.php on line 4

The file adminsetting.php is located in the same dir as index.php and exists.

I've double checked everything I can think of, php is running under the current user, all the ownership and permissions are correct.

I can't figure out why this file cannot be found.

Do I need a separate location block in my vhost.conf for this directory?

--EDIT-- Additional code was requested:

from index.php:

$base_path=substr($_SERVER['SCRIPT_FILENAME'] , 0 , -strlen($_SERVER['PHP_SELF'])+0).dirname($_SERVER['PHP_SELF']);
require_once(dirname(__FILE__) . '/adminsetting.php');
setcookie("usercheck", " ", time()-60*5);
... etc ...

From adminsetting.php:

$site_title="Power Link Generator v4.8";
... etc ...

IF the adminsetting file is being included ... why would the called variables not be found?

图片转代码服务由CSDN问答提供 功能建议

使用Nginx在CentOS 6.4 x64上运行PHP 5.5.5 FPM / FastCGI。 < pre> require_once(dirname(__ FILE__)。'/ adminsetting.php')或die();


(include_path ='。:/ usr / share / pear:/ usr / share / php')失败 /home/vincek/public_html/plg/index.php在第4行

文件 adminsetting.php 位于同一个目录中 as index.php 并且存在。

我已经仔细检查了我能想到的一切,php在当前用户下运行,所有的所有权和权限都是 正确。


我的vhost.conf中是否需要一个单独的位置块? 这个目录?

- 编辑 - 请求附加代码:

来自index.php: < pre> session_start(); $ base_path = substr($ _ SERVER ['SCRIPT_FILENAME'],0 ,-strlen($ _ SERVER ['PHP_SELF'])+ 0).dirname($ _ SERVER ['PHP_SELF']); require_once(dirname(__ FILE__)。 '/adminsetting.php'); setcookie("usercheck“,”“,time() - 60 * 5); include($ require_path。”/ functions.php“); if($ datastoreselected ==”2 “)include_once($ mysql_path。”/ connection.php“); include(”header.php“); include(”side.php“); ... etc ...


  $ root_path =“/ home / vincek / public_html / plg”; 
 $ base_path =“  /home/vincek/public_html/plg";
$base_url="http://vincek.co/plg  /“; 
 $ site_title =”Power Link Generator v4.8“; 
 $ require_path =”/ home / vincek / public_html / plg / include“; 
 $ template_path =”/ home / vincek / public_html / plg / 模板 “; \ N $ mysql_path =”/家/ vincek /的public_html / PLG / MySQL的 “; \ N $ IMAGE_PATH =” http://vincek.co/plg/images “; \ N $ adminbase =”/家/ vincek  / public_html /“; 
 ... etc ... 

如果包含 adminsetting 文件...为什么会 找不到被调用的变量?

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • dongpei3245 2013-11-01 23:08

    Require does not return a value, so it will always die at your or die(). Use

    require_once(dirname(__FILE__) . '/adminsetting.php');

    If it fails, it will cause a fatal error anyway. That's what require does: it includes a script, or dies on failure


    Your adminsetting file is being interpreted as text and I can't understand why. It may have some character that is messing with you <? code blocks. I've seen it happen with XML files having a null character (after some wiseguy edited the XML file with Word, and waited for my parser to do the rest). My best suggestion for now is to move the adminsetting file somewhere else, create a new adminsetting file, write the php code blocks yourself and just copy the rest of the code in the new file. The problem has to be the adminsetting file, nothing else.

    解决 无用
    打赏 举报
  • dongyuxiao6295 2013-11-01 23:20

    The trap is that require_once is a statement, not a function, so the brackets around the filename are misleading. What actually runs is the same as require_once ('something.php' or die); which becomes require_once true; and thence require_once '1';, which explains the error message.

    As others have pointed out, require_once will die on its own anyway, but if you did want to use include_once with this idiom, you need to arrange the brackets differently: (include_once 'something.php') or die;

    解决 无用
    打赏 举报
  • doudeng5218 2014-02-28 13:27





    in your included file.

    <? can't be used in the latest php releases (if you do not make configuration changes).

    解决 无用
    打赏 举报

相关推荐 更多相似问题