Webmonkey Ash - Directory Script

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Maxaipa
Forum Newbie
Posts: 17
Joined: Sat May 10, 2003 6:08 pm

Webmonkey Ash - Directory Script

Post by Maxaipa »

Greetings all,

Been a while since I've posted and I really hope someone can answer this one for me.

I have integrated Ash Young's directory script into an existing test site: the script can be found here:

http://evoluted.net/archives/2005/08/di ... isti_2.php

The script is called index.php by default, but I've renamed it to content14.php so as to be able to use the following php:

Code: Select all

<?	$filename = 'content' . intval($_GET['c']) . '.php';
	  if( !file_exists($filename) ) { // use default filename if file is absent 
      $filename = 'content.php'; 
    }
  	  include($filename); ?>
The listing appears at the intended location in the main page (my existing index.php) and seems to work as expected for the most part.
Within the script, I have $showdirs = true and the directories do, in fact, show up in the listing. When clicking on any 'file', I'm asked to either save it, or the appropriate plugin opens to read the file. However, clicking on a 'directory' loads the 'default file' (as in the code above) and I never see the content of the directory.

If I leave the script as is and call it in the browser as http://.../index.php, all functions work properly. After numerous hours of "tinkering", I've narrowed it down the $_SERVER[PHP_SELF] calls at lines 354 and 362 of the script - changing them to 'index.php?c=14' stops the default file from loading, but still doesn't show the directory content.

I would be incredibly grateful if someone would put me out of my misery and give some idea what the problem might be.

Many thanks and Happy '06 to everyone.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

PHP self doesn't include any GET arguments. $_SERVER['PHP_SELF'] for the page index.php?c=14 will be index.php. Try using $_SERVER['REQUEST_URI'] instead.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Maxaipa
Forum Newbie
Posts: 17
Joined: Sat May 10, 2003 6:08 pm

Post by Maxaipa »

Thanks Pickle,

The $_SERVER['REQUEST_URI'] was one of the first things that I tried but it has the same effect as using 'index.php?c=14'. The listing remains static when clicking on the directories and the content isn't loaded into the page. The address bar indicates that the directory has been selected, but that's it - each subsequent selection is appended to the first in the address bar. I'm trying to figure out what needs to be changed to accommodate this script within the construct of the code mentioned above. As I mentioned, if the page is left on it's own, it works as expected. Driving me nuts, quite frankly.

I certainly appreciate your suggestion - please let me know if you think of anything else that might work.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

So when you click on a directory, does a new page load up but with none of the content showing? Or does the link even take you there? If I understand you correctly, the link is correct, it's just that the script doesn't display the content?

If the URL seems correct, I'd look around line 216 and see what directory is actually being opened.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

The script is looking for a file with the name "contentXX.php" where XX is the passed value of the query string var "c". If it doesn't find the file it defaults to the default page. What checks do you have in place for finding folders?
Last edited by RobertGonzalez on Fri Jan 06, 2006 4:03 pm, edited 1 time in total.
Maxaipa
Forum Newbie
Posts: 17
Joined: Sat May 10, 2003 6:08 pm

Post by Maxaipa »

With $_SERVER['PHP_SELF'], the default 'content' page loads when a directory is selected.
With $_SERVER['REQUEST_URI'}, the page does nothing but append the URL in the address bar - no content loads.
With 'index.php?=14', it has basically the same affect as REQUEST_URI, only the URL does not get appended with each subsequent selection and still no content loads.

I'm not quite sure what I'm looking for at around line 216 - are you referring to the 'clearstatcache' function?
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

In my source, (sorry I should have said line 213), it calls opendir() on a variable $opendir. Maybe it's not opening the correct directory?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Maxaipa
Forum Newbie
Posts: 17
Joined: Sat May 10, 2003 6:08 pm

Post by Maxaipa »

Hi Everah,

Every page that I intend to load into that area is named contentxx.php - the directories themselves are not. I have the script path set to one directory with a number of subdirectories and numerous files - the files seem to be fine and I changed the '$baseurl' to index.php?c=14 to fix the problem with sorting by columns (File, Size or Modified). It's now just a matter of getting those directories to load back into 'index.php?c=14'.

I hope that makes sense.
Maxaipa
Forum Newbie
Posts: 17
Joined: Sat May 10, 2003 6:08 pm

Post by Maxaipa »

Sorry Everah,

Too quick on the submit button.

The folder checks that you refer to, I presume that would have to included in the code I quoted at the top of this thread?
Maxaipa
Forum Newbie
Posts: 17
Joined: Sat May 10, 2003 6:08 pm

Post by Maxaipa »

Everah,

Thank you for the hint - I believe you're correct. I was too busy looking at the directory script and didn't think to check mine.

I've tried a few things but can't seem to get it right. Would you be so kind as to give me an example of code to check for folders? It would be so greatly appreciated, at this point.

Pickle,

Thanks very much for your input!
Post Reply