【问题标题】:require_once() [function.require]: Failed opening requiredrequire_once() [function.require]:需要打开失败
【发布时间】:2014-06-12 10:21:36
【问题描述】:

我一直在为这个寻找解决方案,但似乎对我没有任何用处,问题是我已经在其他项目中使用 require_once 与相同的库 (PHPExcel) 并且工作得很好,但现在我没有不知道怎么回事。

我在两个项目中都使用了 CodeIgniter,但我不知道是 PHP 版本问题还是我做错了什么。 所以,这里是代码:

$this->load->library('PHPExcel');
require_once (base_url().'applications/proyect/libraries/PHPExcel/Cell/AdvancedValueBinder.php');

并显示:

A PHP Error was encountered

Severity: Warning

Message: Users::require_once(http://localhost/my_proyect/applications/proyect/libraries/PHPExcel/Cell/AdvancedValueBinder.php) [function.Usuarios-require-once]: failed to open stream: 
An error occurred during the connection attempt because the connected party did not properly respond after a period of time, or there was an error in the connection established because connected host has failed to respond

Fatal error: Users::require_once() [function.require]: 
Failed opening required 'http://localhost/my_proyect/applications/proyect/libraries/PHPExcel/Cell/AdvancedValueBinder.php' (include_path='.;C:\php5\pear'

我不确定C:\php5\pear 是什么,但我无法处理require_once 问题。

【问题讨论】:

    标签: php codeigniter require-once


    【解决方案1】:

    尝试以正确的方式使用 codeigniter。

    建议:因为它是一个库,你不必精确地包含它。将库文件移动到applications/libraries 目录并 -


    1) 可以在config/autoload.php自动加载

    $autoload['libraries'] = array('my_library');
    


    2) 或者您可以专门加载到所需的控制器中

    <?php
    class Something extends MY_Controller
    {
        public function __construct()
       {
            parent::__construct();
            $this->load->library('my_library');
       }
    
       public function my_function()
       {
            ...
       }
    }
    

    【讨论】:

    • 谢谢,我正在使用库文件夹中的 phpExcel 并调用 load->library 和 phpExcel 现在工作正常,我这样做是因为我在早期项目中遇到了一些问题,它必须使用 require_once。问题就在那里,但我不必再使用它了,所以这部分解决了
    • 很高兴它有帮助!部分;)
    【解决方案2】:

    你不能用

    base_url();
    

    你可以使用

    APPPATH
    

    它是恒定的

       require_once(APPPATH.'applications/proyect/libraries/PHPExcel/Cell/AdvancedValueBinder.php');
    

    【讨论】:

      【解决方案3】:

      您正试图通过 HTTP 连接require 文件,但连接失败。您应该尽可能使用磁盘路径require 文件。

      【讨论】:

      • 嗯我不认为使用磁盘路径对我有用,这就是我使用 base_url() 的原因,但是谢谢!
      • 啊,那是因为我正在与没有使用 codeigniter 的 exp 的工作队友一起工作,并且应用程序将由他们安装,我暂时在这里,我不会在这里他们必须进行安装和未来的迁移,我想你是说我需要做的是放置绝对路径?
      • 是的,可能最好的办法是让自己成为config.php$codeIgniterPath = '/foo';,然后使用require_once $codeIgniterPath . '/whatever.php';,然后当它被部署时,其他人所要做的就是改变路径在config.php.
      猜你喜欢
      • 2011-08-04
      • 1970-01-01
      • 2011-10-17
      • 1970-01-01
      • 2014-10-21
      • 2016-07-06
      • 2017-07-19
      相关资源
      最近更新 更多