PhpExcel:致命错误:类“PHPExcel_Shared_ZipStreamWrapper”

发布于 2024-12-29 22:56:33 字数 502 浏览 6 评论 0原文

我遇到过这个错误

致命错误:在第 29 行的 \VBOXSVR\ACACIASOFT\apc\spreadsheet\lib\phpexcel\PHPExcel\Autoloader.php 中找不到类“PHPExcel_Shared_ZipStreamWrapper”

我当前的设置是: 主机:Windows 7 查看解决方案的地方

:这是我从 svn Virtual Box Guest Machine : :Windows XP :我的apache、php、mysql安装在哪里。 :我还在虚拟机上添加了共享目录,以便我将其用作文档根位置

当我更改文档根时,我的困境开始了。它给我的 phpexcel 模块带来错误,但是当我改回 documentroot c:/program files/apache... 时,将项目复制到此目录。这不会带来任何错误。

I have encountered this error

Fatal error: Class 'PHPExcel_Shared_ZipStreamWrapper' not found in \VBOXSVR\ACACIASOFT\apc\spreadsheet\lib\phpexcel\PHPExcel\Autoloader.php on line 29

My currrent setup is :
Host Machine : Windows 7
: this is where i check out my solution from svn

Virtual Box Guest Machine :
: Windows XP
: where my apache, php, mysql installed.
: I have also added the shared directory on my virtual box so that i will use this as the documentroot location

My dilemma started when i change the documentroot. it bring error on my phpexcel modules but when i changed back the documentroot c:/program files/apache.... copy the project to this directory. this will not bring any error.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

没有你我更好 2025-01-05 22:56:33

同样的问题困扰了我一整天。
我发现,如果您之前在 spl 中注册了自己的自动加载器函数,那么如果您的自动加载器无法加载所需的类,则必须返回 false,如下所示:

spl_autoload_register('my_autoload');
function my_autoload($className)
{
    if(file_exists(CLASS_PREFIX.".$className.php"))
    {
        require_once(CLASS_PREFIX.".$className.php");
    }
    else
    {
        return false;
    }
}

The same problem has been nagging me to death for a whole day.
I found out that if you have your own autoloader function previously registered with spl, then you'll have to return false in the event your autoloader fails to load the required class, like this:

spl_autoload_register('my_autoload');
function my_autoload($className)
{
    if(file_exists(CLASS_PREFIX.".$className.php"))
    {
        require_once(CLASS_PREFIX.".$className.php");
    }
    else
    {
        return false;
    }
}
九公里浅绿 2025-01-05 22:56:33

看起来您正在运行一些其他带有自己的自动加载器的库,这些库会干扰 PHPExcel 自动加载器。最新的SVN代码已被修改以防止此问题。

在 /Classes/PHPExcel/Autoloader.php 脚本本身中,将:更改

public static function Register() {
    return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
}   //  function Register()

public static function Register() {
    if (function_exists('__autoload')) {
        //    Register any existing autoloader function with SPL, so we don't get any clashes
        spl_autoload_register('__autoload');
    }
    //    Register ourselves with SPL
    return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
}    //    function Register()

Looks like you're running some other library with its own autoloader that interferes with the PHPExcel autoloader. The latest SVN code has been modified to prevent this problem.

In the /Classes/PHPExcel/Autoloader.php script itself, change:

public static function Register() {
    return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
}   //  function Register()

to

public static function Register() {
    if (function_exists('__autoload')) {
        //    Register any existing autoloader function with SPL, so we don't get any clashes
        spl_autoload_register('__autoload');
    }
    //    Register ourselves with SPL
    return spl_autoload_register(array('PHPExcel_Autoloader', 'Load'));
}    //    function Register()
波浪屿的海角声 2025-01-05 22:56:33

如果有人碰巧使用的是Linux,那么这个错误可能是由不正确的使用权限引起的。

我遇到了同样的问题,但我更改了“共享”文件夹的所有者,并将其设置为“www-data”用户,这是我系统上的 apache 用户(chown www-data:www-data Shared)。这修复了“未找到类‘PHPExcel_Shared_ZipStreamWrapper’”错误。

但这并不是完整的修复,您真正需要做的是确保 PHPExcel 文件夹中的文件夹和文件分配给正确的用户,并且他们具有正确的权限。操作方法如下:

您需要将 PHPExcel 文件夹及其中的每个项目分配给 www-data 用户,以便 Apache 可以访问这些文件。确保您位于 PHPExcel 文件夹下一级,然后运行以下命令:

sudo chown -R www-data:www-data PHPExcel

就是这样。 Apache 应该能够访问所有文件并且错误应该得到解决。

If anyone happens to be on Linux, then this error can be caused by incorrect usage rights.

I had this same issue, but I changed the owner of the 'Shared' folder, and set it to be 'www-data' user, which is the apache user on my system (chown www-data:www-data Shared). This fixed the "Class 'PHPExcel_Shared_ZipStreamWrapper' not found" error.

Yet this is not the full fix, What you really need to do is make sure the folders and files in the PHPExcel folder are assigned to the correct user, and that they have the correct rights. Here is how you do it:

You need to assign the PHPExcel folder and every item in it to the www-data user so Apache can access the files. Make sure you are one level below your PHPExcel folder and then run this command:

sudo chown -R www-data:www-data PHPExcel

And that is that it. Apache should be able to access all the files and the error should be resolved.

我不是你的备胎 2025-01-05 22:56:33

您必须在 php 扩展上启用 zip dll

You must enable on php extension the zip dll

彻夜缠绵 2025-01-05 22:56:33

好吧,我知道已经是一年前的事了,但是由于几天前我的设置(在具有明确用户权限的 Active Directory 网络中运行 Windows 7 Professional 的虚拟机)出现了这个问题,我想分享我的解决方案,也许这会有所帮助其他人为了节省一些时间:

我发现了两个问题(仅在 WINDOWS 主机上!):

  • PHPEXCEL_ROOT-Constant 是用错误的目录分隔符定义的

MY解决方案:更改 php 代码以在定义中使用 DIRECTORY_SEPARATOR 常量
在文件中:PHPExcel.php(大约第 32 行)如下所示:

//OLD: define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
define('PHPEXCEL_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);

还有 2 个文件需要更改:“IOFactory.php”和“Settings.php”(第 34 行):

//OLD: define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
define('PHPEXCEL_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR);
  • PHP 函数“is_read”并不总是返回Windows 主机上的结果正确,在我的例子中,文件是可读的,但结果是错误

我的解决方法:要解决此错误,您可以删除文件“autoload.php”中的“is_read”检查,将第 77 行更改为:

// if ((file_exists($pClassFilePath) === FALSE) || (is_readable($pClassFilePath) === FALSE)) {
if (file_exists($pClassFilePath) === FALSE) {

Ok I know it's already a year ago, but since this problem occured to my setup (Virtual Machine running Windows 7 Professional in an Active Directory network with explicit user rights) just a few days ago i wanted to share my solution, maybe this will help others to save some time:

I figured out 2 problems (only on WINDOWS HOSTS!):

  • the PHPEXCEL_ROOT-Constant is defined with wrong directory seperators

MY SOLUTION: change the php code to use the DIRECTORY_SEPARATOR constant in the defitinions
in the file: PHPExcel.php (around Line 32) like this:

//OLD: define('PHPEXCEL_ROOT', dirname(__FILE__) . '/');
define('PHPEXCEL_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR);

there are 2 more files to change: "IOFactory.php" and "Settings.php" (Line 34) to:

//OLD: define('PHPEXCEL_ROOT', dirname(__FILE__) . '/../');
define('PHPEXCEL_ROOT', dirname(__FILE__) . DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR);
  • the PHP function "is_readable" does not always return correct results on Windows hosts, in my case the file was readable but the result was false.

MY WORKAROUND: To work around this Bug, you can remove the "is_readable" check in the file "autoload.php" change line 77 to:

// if ((file_exists($pClassFilePath) === FALSE) || (is_readable($pClassFilePath) === FALSE)) {
if (file_exists($pClassFilePath) === FALSE) {
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文