Current path ./ not working with includes, PHP5 on Windows

Need help installing PHP, configuring a script, or configuring a server? Then come on in and post your questions! We'll try to help the best we can!

Moderator: General Moderators

Post Reply
MoogPHP
Forum Newbie
Posts: 4
Joined: Fri Jul 28, 2006 2:00 pm

Current path ./ not working with includes, PHP5 on Windows

Post by MoogPHP »

I have just setup a PHP5/Apache server on Windows 2003. The install worked fine and PHP is running fine, as is Apache.

We are migrating from Linux to Windows. I have many, many files and even downloaded third-party applications and files that use the following method of including and requiring:

Code: Select all

include("./foo.php");
By all rights, this should include the file 'foo.php' that is located in the current directory, but it's not.

Code: Select all

Warning: include(./foo.php) [function.include]: failed to open stream: No such file or directory in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test.php on line 3

Warning: include() [function.include]: Failed opening './foo.php' for inclusion (include_path='.;c:\php;c:\php\pear') in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test.php on line 3
However, if I change the include to:

Code: Select all

include("foo.php");
It works just fine. I expected it to work that way, but the problem is all my code is using ./ to denote the current directory, as is thirdparty stuff.

The 'path_include' in the php.ini is commented out, as it is by default. I've looked at theories elsewhere that suggest this is the problem, but nothing has worked, so I restored the php.ini to almost-default settings.

Beyond the include() function, other functions that work on files, like XSL functions, are also not finding files.

Code: Select all

$xml = new DOMDocument;
$xml->load('collection.xml');
In this case, the 'collection.xml' file is in the same folder as the script running the function, but the function looks in the htdocs\ path for the file. Changing it to './collection.xml' doesn't work either.

I've spent most of the day trying to find a solution - or at least a definite answer that says using ./ will or will not work.

If anyone has any info or knows if ./ can be used on a Windows system, please reply.

I appreciate any and all comments on this topic.
Thanks,
~Brian, Ohio USA
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

getcwd() may be of interest, so may realpath().
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Can you confirm for us that this file...

C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test.php

exists within that path?
timvw
DevNet Master
Posts: 4897
Joined: Mon Jan 19, 2004 11:11 pm
Location: Leuven, Belgium

Post by timvw »

If i remember well, the xml lib doesn't use the php include_path but has one of it's own.. I remember that it's possible (but now how) to change the include path of the document.... If i'm not mistaken this should be a workaround:

Code: Select all

$dom = new DomDocument();
$dom->Load(realpath('./blah.xml'));
MoogPHP
Forum Newbie
Posts: 4
Joined: Fri Jul 28, 2006 2:00 pm

Post by MoogPHP »

Yes, the path of the file running is:
C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\test.php

test.php and foo.php are both that folder.

And I understand the alternate solutions to this problem, like using the realpath() and other such functions, and I appreciate all that feedback.

But what I really want to know is if ./ can be used with includes or not. If not, then I will look for alternate solutions within other functions. There is a huge pile of code with ./ includes and I'm trying avoid recoding all of them. If it turns out ./ doesn't work on Windows, then it doesn't work - but as a long user of PHP and web servers in general, I don't understand why ./ wouldn't work, regardless of platform.

Thanks for anymore help on this. I have continued my quest for an answer all without any good leads.

~Brian
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

It should work. I have that root designator in almost all of my apps. I really can't think of what could cause that issue except maybe an issue with conflicting variable names, which I highly doubt since you didn't have variables in your include names.
MoogPHP
Forum Newbie
Posts: 4
Joined: Fri Jul 28, 2006 2:00 pm

Post by MoogPHP »

Thanks, Everah...at least I know that someone does have it working, so that's encouraging. At least it is possible.

I'll keep trying different things in hopes of getting it work.

If anyone has a similar issue or, better yet, had the same situation and resolved it, please reply here with steps to the solution.

Again...PHP5 on Windows 2003 running Apache 2.2

Thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Just a quick thought, but does that designator choke on anything else? Like

Code: Select all

if (file_exists('./file.php'))
{
   echo 'I exist!';
}
Or something...
MoogPHP
Forum Newbie
Posts: 4
Joined: Fri Jul 28, 2006 2:00 pm

Post by MoogPHP »

Yes, it chokes on that type of checking too. I think it was some sort of overarching path problem, because even functions like file() had issues when looking for files that start with ./ in their path.

I posted on some other forums yesterday without any luck, so I took the easy way out and resorted to alternatives - I installed XAMPP (http://www.apachefriends.org)

For whatever reason, the XAMPP install works perfectly and as expected with the ./ includes. I would go through their .conf files, but they are all jacked up with XAMPP changes so it is hard to tell what is there lines versus the original Apache lines.

I'm going through and trying to lock down XAMPP and then going to do some speed/performance tests to see if XAMPP is really suitable for what I'm doing (intranet). I have used XAMPP at home for local development, but never for a production servers, albeit and internal server. If it holds up, then I have no problem using it, it is a very easy install to do and manage. File structure is a little awkward, but it's dealable.

But...that being said, for everyone else that comes across this, if you find a solution to the ./ problem when installing Apache and PHP independently, please post a solution or thoughts here. I took the easy way out, but that doesn't mean it's the best way.

And thanks, Everah for your insights and thoughts...
~Brian
ragingpugh
Forum Newbie
Posts: 2
Joined: Sat Aug 12, 2006 12:14 pm

Anybody solve this problem?

Post by ragingpugh »

I've been having the same exact problem as Moog but on a Linux server running apache 2 and php5. When the ./ is removed, it works fine but the xml loading still can't seem to find the file with our without the ./

Please let me know if you guys were able to solve this. Thanks!
ragingpugh
Forum Newbie
Posts: 2
Joined: Sat Aug 12, 2006 12:14 pm

Finally...

Post by ragingpugh »

Well, I just figured it out all of a sudden. I used the getcwd() command to figure out from where the crond was executing from. It was being excuted from /root directory, so I set the HOME variable to the root directory of my web site.

Here's what the crontab ended up looking like:

Code: Select all

PATH=/usr/bin:/bin:/usr/local/apache2/bin
HOME=/var/www/html

* * * * * php /var/www/html/cronjob.php
Hope this helps somebody.
Post Reply