Jump to content

Recommended Posts

Hey guys,

 

I have an include as follows;

 

include_once(__FILE__."/../Page.inc.php");

 

which has been working fine. Now in PHP 5.3.x I get a warning;

 

Warning:  include_once(C:\xampp\htdocs\example.com\site\pageTemplates\classes\PublicPage.inc.php/../Page.inc.php) [function.include-once]: failed to open stream: No such file or directory in C:\xampp\htdocs\example.com\site\pageTemplates\classes\PublicPage.inc.php on line 7

 

Changing the code to;

 

include_once(dirname(__FILE__)."/Page.inc.php");

 

Can anyone explain why this is happening?

Link to comment
https://forums.phpfreaks.com/topic/181879-upward-linking-in-include_once/
Share on other sites

My bet is the configuration settings in php 5. The old version of PHP could have had a different include path that the new one does not have, either it was defaulted in the older version of PHP or was added manually.

 

Alternatively, I could be completely wrong and they just changed how __FILE__ worked and it now works so that it actually includes the file instead of the directory as it previously did? The only way to get to the bottom is go look at release notes on php.net :)

Try this

 

include_once(__DIR__ . DIRECTORY_SEPERATOR . 'Page.inc.php');

 

__DIR__ is only available in PHP 5.3.x, and though that's what I'm using locally, it's not available on the production server.

 

My bet is the configuration settings in php 5. The old version of PHP could have had a different include path that the new one does not have, either it was defaulted in the older version of PHP or was added manually.

 

I can't see anything wrong in the settings, and it should skip over the include paths (as the fiels aren't there) and attempt to resolve the absolute path.

 

Alternatively, I could be completely wrong and they just changed how __FILE__ worked and it now works so that it actually includes the file instead of the directory as it previously did? The only way to get to the bottom is go look at release notes on php.net :)

 

I've had a quick look through the release notes, will have to look a little harder as this is causing hassles all across the system!

 

 

Cheers guys,

gevans

Per the php manual the __FILE__ magic constant returns the path and the file name.  Its strange that the way you have been doing it was working correctly since it was going <file>/../ which isnt a valid path.  so your better changing it now to save any future headaches.

 

Maybe this way? 

 

include_once(dirname(__FILE__)  . DIRECTORY_SEPARATOR . 'Page.inc.php'); 

As mentioned in my first post it was fixed with a 'similar' solution (not using DIRECTORY_SEPERATOR).

 

I'm doing this for another company so am not gonna fix there code unless I'm getting paid for it. Just wanted to make sure it wasn't something caused by my setup!

 

Thanks again,

gevans

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.