PHPExcel showing error on remote server

I am using PHPExcel in my php classes to generate xls file. The code works fine on my localhost but shows errors on the remote server.

Errors:

 <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 />

      

I searched the web and found a solution to update the php version and include some php libraries, but already updated my remote server. Can anyone tell me what could be causing these errors on the remote server?

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

+1


source to share


4 answers


PHPExcel file is not

PHPExcel_Shared_String.class.php

      

it

PHPExcel/Shared/String.php

      

It looks like you might have an autoloader that clashes with the PHPExcel autoloader: try using SPL_autoload_register ()

EDIT

Quoting from PHP docs (section 3.2 of developer documentation)



PHPExcel implements an autoloader or "lazy loader", which means that you don't need to include every file in PHPExcel. You only need to include the PHPExcel class source file, then the autoloader will include other class files as needed, so only those files that your script actually require will be loaded into PHP memory. The main advantage of this is that it reduces the memory footprint of PHPExcel itself so that it uses less PHP memory.

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

function __autoload($class) {
    ...
}

      

Do this instead:

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

      

After that, the autoloader will be combined with the PHPExcel autoloader.

+5


source


What is the full path to the file PHPExcel_Shared_String.class.php

?

The error messages say that on line 13 of your index.php

it cannot contain the file here

/home/example/../inc/classes/PHPExcel_Shared_String.class.php

      



and can't find the file here:

/home/example/../inc/classes/Classes/inc/classes/PHPExcel_Shared_String.class.php

      

0


source


The problem is that autoloaders can conflict. You need to make sure your autoloader is trying to load the PHPExcel file. This was the case in my situation.

The PHPExcel autoloader did just fine, but my autoloader also got into action and it failed. I put code (stolen from PHPExcel autoloader) that was checked to make sure my autoloader was only trying to load MY code.

So, for example, in PHPExcel, the autoloader starts with:

if ((class_exists($pClassName,FALSE)) || (strpos($pClassName, 'PHPExcel') !== 0)) {
    //    Either already loaded, or not a PHPExcel class request
    return FALSE;
}

      

If you do something like this (or check for NOT PHPExcel), you will find it works fine.

0


source


I had the same problem with 'Failed opening' inc / classes / PHPExcel_Shared_String.class.php '. It worked well locally (Mac), but not remote on Linux. The solution was uppercase writing "PHPExcel". I changed it to "phpexcel", same with include in php. This caused this error.

Let the "PHPExcel" folder not "phpexcel" and include it also with an uppercase letter in php

include_once 'PHPExcel/PHPExcel.php';

      

then everything works fine.

0


source







All Articles