...

View Full Version : PHP reading outside its parent directory.



Kolusion
08-22-2011, 03:17 PM
I've got:

/A/index.html
/A/1/index.listing
/A/2/index.listing
/A/3/index.listing

In index.html, I've got the following PHP code:

<?php
$files = glob('./*/*.listing');
foreach ($files as $file)
{
include $file;
}
?>

As you can see, what PHP code does is include()'s all the index.listing files.

I then create a clone of the A directory and alter the HTML in the .listing files so can tell the difference between A & B when they render:

/B/index.html
/B/1/index.listing
/B/2/index.listing
/B/3/index.listing

The issue I am having is "/B/index.html" is ()including the .listing files from the /A/*/ directory, when it should be including them from the /B/*/ directory.
I can't understand why this is happening and hoping someone could shed some light on the issue?

JamesOxford
08-22-2011, 03:59 PM
I am not positive about this because I have never included files that way before. Does it have anything to do with the fact that you have two (*). Star means anything matching the criteria, the criteria being one folder forward for the first star. So I would think it would include A, B and C...but like I said, I have never included files that way. It is possible that it is just including the first thing matching the criteria, which would be the 'A' directory index. I am just guessing, but it is a somewhat educated guess.

Kolusion
08-22-2011, 04:04 PM
Hey dude,

Nah it couldn't be that reason because index.html is being execute inside the B directories. Thats what I don't understand... Its including files from a parent directory (A), when it should be including them from child directory /*/. Fully strange huh!

JamesOxford
08-22-2011, 04:08 PM
I said index, but I meant *.listing. I think it is reading anything two folders forward that has a .listing file name. Does that change anything?

Kolusion
08-22-2011, 04:13 PM
No, index.html is being ran inside the A and B directories.

Kolusion
08-22-2011, 06:05 PM
Never mind, there was nothing wrong with the code. It was another problem. The code works.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum