Reputation: 2968
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.
Errors are :
<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 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 ?
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.
Upvotes: 1
Views: 5430
Reputation: 41
I had the same Problem with "Failed opening 'inc/classes/PHPExcel_Shared_String.class.php'". It worked well local (Mac), but not remote on linux. The solution was the spelling with the upper case of 'PHPExcel'. I changed it to 'phpexcel', same with the include in php. This generated this error.
Let the folder spelling 'PHPExcel' not 'phpexcel' and include it also with uppercase letter in php
include_once 'PHPExcel/PHPExcel.php';
then everything is working fine.
Upvotes: 0
Reputation: 148
The problem is that autoloaders can conflict. You need to check to be sure if your autoloader is trying to load a PHPExcel file. That was the case in my situation.
The PHPExcel autoloader was doing it just fine, but MY autoloader was also getting into the act, and it was failing. I put in code (stolen from PHPExcel's autoloader) that checked to be sure my autoloader was only trying to autoload 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 similar (or check for NOT PHPExcel) you will find it works fine.
Upvotes: 0
Reputation: 212522
The PHPExcel file isn't
PHPExcel_Shared_String.class.php
it's
PHPExcel/Shared/String.php
It looks as though you may have an autoloader that's clashing with the PHPExcel autoloader: try using SPL_autoload_register()
EDIT
Quoting from the PHP docs (section 3.2 of the developer documentation)
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.
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');
Your autoloader will then co-exist with the autoloader of PHPExcel.
Upvotes: 5
Reputation: 13002
What's the full filepath of the PHPExcel_Shared_String.class.php
?
The error messages are saying that on line 13 of your index.php
it can't include a file from here
/home/example/../inc/classes/PHPExcel_Shared_String.class.php
nor can it find the file here:
/home/example/../inc/classes/Classes/inc/classes/PHPExcel_Shared_String.class.php
Upvotes: 0