警告:包括(PHPExcel.php):无法打开流:没有这样的文件或目录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/20621834/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 03:20:55  来源:igfitidea点击:

Warning: include(PHPExcel.php): failed to open stream: No such file or directory

phpincludexamppphpexcelinclude-path

提问by Phil

Im trying to implement Converting single sheet in an XLS file to CSV with PHPExcel - Memory exhaustedbut got stuck in the PHP Excel loading process.

我正在尝试使用 PHPExcel实现将 XLS 文件中的单个工作表转换为 CSV - 内存已耗尽但卡在 PHP Excel 加载过程中。

I downloaded the pack (http://phpexcel.codeplex.com/) and, following the install instructions, copied the folder 'Classes' to three directories:

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

1) C:\xampp\htdocs\mycode - just my current working directory

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

2) C:\xampp\php\pear - bcs its what i get when I echo get_include_path();

2) C:\xampp\php\pear - bcs 它是我得到的 echo get_include_path();

and

3) C:\xampp\php\pear\PEAR - you know, just in case...

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

still when I run:

当我运行时仍然:

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

I get the following error messages:

我收到以下错误消息:

Warning: include(PHPExcel.php): failed to open stream: No such file or directory in C:\xampp\htdocs\mycode\paths.php on line 5

Warning: include(): Failed opening 'PHPExcel.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\mycode\paths.php on line 5

Warning: include(PHPExcel/IOFactory.php): failed to open stream: No such file or directory in C:\xampp\htdocs\mycode\paths.php on line 6

Warning: include(): Failed opening 'PHPExcel/IOFactory.php' for inclusion (include_path='.;C:\xampp\php\PEAR') in C:\xampp\htdocs\mycode\paths.php on line 6

警告: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 行失败

tks in advance...

提前tks...

回答by Phil

...copied the folder 'Classes' to three directories

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

Seems the hint is right there. Shouldn't it be

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

require_once 'Classes/PHPExcel.php';

Alternatively, add the Classesfolder to your include path...

或者,将该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';

回答by H.Gmz

In my case i juste had to replace my

就我而言,我不得不更换我的

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

by this:

这样:

require_once "./classes/Projects.php";

回答by Crackertastic

Generally when you are including files it is going to be relative to the file you are calling the includefrom. Make sure you are looking in the correct directory. I say this because the way you include files seems as if the PHPExcel files should be in the exact same directory, but it looks like you put this into a folder called classes.

通常,当您包含文件时,它将与您正在调用的文件相关include。确保您在正确的目录中查找。我这样说是因为你包含文件的方式看起来好像 PHPExcel 文件应该在完全相同的目录中,但看起来你把它放在一个名为classes.

For example, if your directory structure looks like this:

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

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...)

Then you are including from where index.phpis located. So if PHPExcel is located in the classesfolder, then your includestatement should look like this:

然后你包括来自哪里index.php。因此,如果 PHPExcel 位于classes文件夹中,那么您的include语句应如下所示:

include classes/PHPExcel.phpor include classes/PHPExcel/IOFactory.php

include classes/PHPExcel.php或者 include classes/PHPExcel/IOFactory.php