PHPExcel在远程服务器上显示错误 [英] PHPExcel is showing error on Remote Server

查看:70
本文介绍了PHPExcel在远程服务器上显示错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的php类中使用PHPExcel生成一个xls文件.代码在我的本地主机上运行正常,但是在远程服务器上显示错误.

I am using PHPExcel in my php classes to generate a xls file. Code is perfectly working on my localhost but showing errors on remote server.

错误是:

 <br />
<b>Warning</b>:  include(inc/classes/PHPExcel_Shared_String.class.php): failed to open stream: No such file or directory in <b>/home/example/../index.php</b> on line <b>13</b><br />
<br />
<b>Warning</b>:  include(): Failed opening 'inc/classes/PHPExcel_Shared_String.class.php' for inclusion (include_path='.:/usr/share/pear:/home/example/../inc/classes/Classes/') in <b>/home/example/../index.php</b> on line <b>13</b><br />

我一直在Internet上搜索,找到了一种解决方案来更新php版本并启用一些php库,但是该解决方案已在我的远程服务器上进行了更新.谁能告诉我远程服务器上这些错误的原因是什么?

I have been searching on internet and found a solution to update php version and enable some php libraries but that is already updated on my remote server. Could anyone tell me what can be the reason of these errors on remote server ?

我正在使用index.php文件,其中有一个默认的__autoloader()函数来加载所有.class文件,另一个文件是excelgenerate.php,在该文件中,我再次使用相同的自动加载器来加载该类文件.在此文件中,我具有一个函数,其中使用PHPExcel代码通过包含PHPExcel.php来生成excel文件.这是我遇到错误的流程.

I am using an index.php file in which I have a default __autoloader() function to load all the .class files and another file named excelgenerate.php in which I am again using same autoloader to load that class file. In this file, I have a function in which I am using PHPExcel code to generate excel file by including PHPExcel.php. This is the flow in which I am getting error.

推荐答案

PHPExcel文件不是

The PHPExcel file isn't

PHPExcel_Shared_String.class.php

PHPExcel/Shared/String.php

似乎您可能有一个与PHPExcel自动加载器冲突的自动加载器:请尝试使用 SPL_autoload_register()

It looks as though you may have an autoloader that's clashing with the PHPExcel autoloader: try using SPL_autoload_register()

编辑

引用PHP文档(开发人员文档的3.2节)

Quoting from the PHP docs (section 3.2 of the developer documentation)

PHPExcel实现了自动加载器或惰性加载器",这意味着不必在PHPExcel中包含每个文件.仅需要包含初始PHPExcel类文件,然后自动加载器将在需要时包含其他类文件,因此只有脚本实际需要的那些文件才会被加载到PHP内存中.这样做的主要好处是,它减少了PHPExcel本身的内存占用,因此使用的PHP内存更少.

PHPExcel implements an autoloader or "lazy loader", which means that it is not necessary to include every file within PHPExcel. It is only necessary to include the initial PHPExcel class file, then the autoloader will include other class files as and when required, so only those files that are actually required by your script will be loaded into PHP memory. The main benefit of this is that it reduces the memory footprint of PHPExcel itself, so that it uses less PHP memory.

如果您自己的脚本已经定义了自动加载功能,则PHPExcel自动加载功能可能会覆盖此功能.例如,如果您有:

If your own scripts already define an autoload function, then this may be overwritten by the PHPExcel autoload function. For example, if you have:

function __autoload($class) {
    ...
}

相反,请执行以下操作:

Do this instead:

function myAutoload($class) {
    ...
}
spl_autoload_register('myAutoload');

您的自动加载器将与PHPExcel的自动加载器共存.

Your autoloader will then co-exist with the autoloader of PHPExcel.

这篇关于PHPExcel在远程服务器上显示错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆