...

View Full Version : Failed opening required (include_path='.;c:\wamp\php\pear')



cmarti10
04-27-2012, 05:09 PM
Hello All,

I have Wamp version 2.2 running php version 5.3.8.

I downloaded PHPPowerPoint so that I can begin creating reports for a customer.

The following line of code is giving me some trouble:


require_once('php_powerpoint/Classes/PHPPowerPoint.php');

I get the following errors:

Warning: require_once(Classes/PHPPowerPoint.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\irma\php_powerpoint\Classes\PHPPowerpoint\Slide.php on line 30

Fatal error: require_once() [function.require]: Failed opening required 'Classes/PHPPowerPoint.php' (include_path='.;c:\wamp\php\pear') in C:\wamp\www\irma\php_powerpoint\Classes\PHPPowerpoint\Slide.php on line 30

I did some searching online and was coming across a lot of information about PEAR. However, I searched my wamp directories and I dont have any PEAR files (like go-pear.bat).

Is PEAR really my problem? Or, is it something else? Thanks in advance for any help :)!

myfayt
04-27-2012, 05:36 PM
The path to PHPPowerPoint.php isn't correct, it's saying the file is missing. So play around with the path to find the right one. That should clear it up.

cmarti10
04-27-2012, 06:22 PM
The file I am trying to display is called powerpoint_report.php. It is located in my root project directory. The file I am trying to include in powerpoint_report.php is called PHPPowerPoint.php which is located in my *root*/php_powerpoint/Classes directory.

So then, isn't the following code correct?


require_once('php_powerpoint/Classes/PHPPowerPoint.php');

Fou-Lu
04-27-2012, 06:24 PM
This has nothing to do with PEAR. This only represents the known path for PHP, which is the running directory, and the pear directory.
The error doesn't match your include:Warning: require_once(Classes/PHPPowerPoint.php) [function.require-once]: failed to open stream: No such file or directory in C:\wamp\www\irma\php_powerpoint\Classes\PHPPowerpoint\Slide.php on line 30

This indicates that you are calling a path under 'Classes/', not 'php_powerpoint/classes'. It is possible that it has it an __autoload or registered autoloader which has caused this.

The inclusion path is the location of the running script. From the slide.php you can include using:


require_once dirname(__FILE__) . '/../PHPPowerPoint.php';

Which will fetch it from the directory above the Slide.php script.

cmarti10
04-27-2012, 06:33 PM
Thanks for the suggestion Fou-Lu.

I tried replacing:


require_once 'Classes/PHPPowerPoint.php';

with your code:


require_once dirname(__FILE__) . '/../PHPPowerPoint.php';

And it worked for that particular include. However, I have approx. 15 other includes listed in the Slide.php file that will need the same type of modification. Instead of applying dirname(__FILE__) to each include, is there another way?

Fou-Lu
04-27-2012, 06:59 PM
No, if you are calling an inclusion with bad paths, you'll need to modify the paths to work either absolute (for which I don't recommend), absolute to server path (which will work except in a command line environment), or relative from file (which I recommend).

The alternative is to register every possible path into the include_path. Can be done at a script level as well using a simple:


set_include_path(get_include_path() . PATH_SEPARATOR . dirname(__FILE__));

But at this point you may as well just append the dirname(__FILE__) (or on newer versions of php __DIR__ will work).
Using an inclusion path will be tricky since the files you want have partial paths which will make finding them a nightmare with an include path.


However, if you are dealing explicitly with class objects, you can use the __autoload or even better an spl_register to add directories for the classes to look through. Works very well with namespaces in particular. This lets you automagically load classes when calling new, so inclusions are no longer required. Personally I still use an include off of the dir since I don't use auto_prepend_file to allow a global inclusion of a file designed to load specific classes.

cmarti10
05-02-2012, 01:57 PM
Thanks for all the help! I've got it working now :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum