Page 1 of 1

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

Posted: Fri Jul 28, 2006 2:17 pm
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

Posted: Fri Jul 28, 2006 2:26 pm
by feyd
getcwd() may be of interest, so may realpath().

Posted: Fri Jul 28, 2006 2:26 pm
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?

Posted: Fri Jul 28, 2006 2:47 pm
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'));

Posted: Fri Jul 28, 2006 3:50 pm
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

Posted: Fri Jul 28, 2006 8:24 pm
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.

Posted: Mon Jul 31, 2006 11:05 am
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

Posted: Mon Jul 31, 2006 9:18 pm
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...

Posted: Tue Aug 01, 2006 9:52 am
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

Anybody solve this problem?

Posted: Sat Aug 12, 2006 12:26 pm
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!

Finally...

Posted: Sat Aug 12, 2006 12:41 pm
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.