【问题标题】:Warning: include(PHPExcel.php): failed to open stream: No such file or directory警告:包含(PHPExcel.php):无法打开流:没有这样的文件或目录
【发布时间】:2014-01-04 11:42:41
【问题描述】:

我正在尝试实现Converting single sheet in an XLS file to CSV with PHPExcel - Memory exhausted,但在 PHP Excel 加载过程中卡住了。

我下载了包 (http://phpexcel.codeplex.com/),并按照安装说明将文件夹“Classes”复制到三个目录:

1) C:\xampp\htdocs\mycode - 只是我当前的工作目录

2) C:\xampp\php\pear - 这是我echo get_include_path();时得到的结果

3) C:\xampp\php\pear\PEAR - 你知道,以防万一......

当我跑步时:

include 'PHPExcel.php';
include 'PHPExcel/IOFactory.php';

我收到以下错误消息:

警告:include(PHPExcel.php):无法打开流:第 5 行的 C:\xampp\htdocs\mycode\paths.php 中没有这样的文件或目录

警告:include():在第 5 行的 C:\xampp\htdocs\mycode\paths.php 中打开 'PHPExcel.php' 以包含 (include_path='.;C:\xampp\php\PEAR') 失败

警告:include(PHPExcel/IOFactory.php):无法打开流:第 6 行的 C:\xampp\htdocs\mycode\paths.php 中没有这样的文件或目录

警告:include():在 C:\xampp\htdocs\mycode\paths.php 中打开 'PHPExcel/IOFactory.php' 以包含 (include_path='.;C:\xampp\php\PEAR') 失败第 6 行

提前通知...

【问题讨论】:

  • 然后,确保所有文件都在正确的文件夹中并且路径正确。我以前使用过那个库,使用它没有问题。
  • @Fred-ii- tks,这对我来说有点新鲜。不就是复制C:\xampp\php\pear 中的“Classes”文件夹吗?如何确定?
  • 我从托管服务器运行它。我不能肯定地说local machine。看看菲尔在下面发布的内容。还要确保文件夹名称拼写正确,字母大小写很重要。 classes 与某些服务器上的 Classes 不同(Unix 和 Windows 完全是两种不同的动物)
  • 经常会遇到这个错误,要快速解决它,请按照以下步骤操作:stackoverflow.com/a/36577021/2873507

标签: php include xampp phpexcel include-path


【解决方案1】:

...将文件夹“Classes”复制到三个目录

似乎提示就在那里。不应该吗

require_once 'Classes/PHPExcel.php';

或者,将Classes 文件夹添加到您的包含路径...

set_include_path(implode(PATH_SEPARATOR, [
    realpath(__DIR__ . '/Classes'), // assuming Classes is in the same directory as this script
    get_include_path()
]));

require_once 'PHPExcel.php';

【讨论】:

  • 对于下一个遇到同样问题的人,解决方法是include 'Classes/PHPExcel.php'; include 'Classes/PHPExcel/IOFactory.php';
  • 又一个“大团圆”
  • 现在有一个针对此常见错误的故障排除清单:stackoverflow.com/a/36577021/2873507
【解决方案2】:

在我的情况下,我只需要更换我的

include "../classes/Projects.php";

通过这个:

require_once "./classes/Projects.php";

【讨论】:

    【解决方案3】:

    通常,当您包含文件时,它将与您调用 include 的文件相关。确保您在正确的目录中查找。我这样说是因为您包含文件的方式似乎 PHPExcel 文件应该位于完全相同的目录中,但看起来您将其放入名为 classes 的文件夹中。

    例如,如果您的目录结构如下所示:

    C:\
       - xampp\
           - htdocs\
               - mycode\
                   - classes\  (where you extracted your files to...)
                       - (more files and subdirectories in here)
                   - index.php (where you are including file into...)
    

    那么您将包括index.php 所在的位置。因此,如果 PHPExcel 位于 classes 文件夹中,那么您的 include 语句应如下所示:

    include classes/PHPExcel.phpinclude classes/PHPExcel/IOFactory.php

    【讨论】:

    • 现在有一个针对此常见错误的故障排除清单:stackoverflow.com/a/36577021/2873507
    【解决方案4】:

    这个模块最初对我有用。但是后来我添加了Yii2,花了很长时间寻找解决问题的方法。对于那些找到这个话题的人,就像我做的那样,并且在 Yii1 中添加了 Yii2,我将离开这个解决方案。

    对我来说首先帮助了这个。

            spl_autoload_unregister(['YiiBase', 'autoload']);
            require_once Yii::app()->params['rootPath'] . '/PHPExcel/Classes/PHPExcel.php';
            spl_autoload_register(['YiiBase', 'autoload']);
    

    当我添加 Yii2 时,我改变了

            spl_autoload_unregister(['Yii', 'autoload']);
            spl_autoload_unregister(['YiiBase', 'autoload']);
            require_once Yii::app()->params['rootPath'] . '/PHPExcel/Classes/PHPExcel.php';
            spl_autoload_register(['YiiBase', 'autoload']);
            spl_autoload_register(['Yii', 'autoload']);
    

    下次使用

      $objPHPExcel = new \PHPExcel();
      ...
      $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    

    【讨论】:

      猜你喜欢
      • 2017-06-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-24
      • 2016-07-24
      • 2017-06-20
      • 2012-11-21
      • 1970-01-01
      相关资源
      最近更新 更多