Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Folder Listing Method
Old 07-15-2006, 08:06 PM Folder Listing Method
Kiros72's Avatar
Average Talker

Posts: 18
Name: Kiros
Location: Albany, LA - USA
Trades: 0
I just got a new website host on June 19th, and I'm already hosting 4 sites for some friends (via subdomains). I've made a section that will show the hosted sites. Though I want it to self-manage itself, meaning automatically updating with a PHP method. I have an idea for it, and I'm trying to implement it, but my method consists of a long if statement with a lot of AND's (&&). My idea is to make the method return a list of folders from the root directory except the ones that apply to my main site (such folders as _private, css, images, forums, cgi-bin). Right now, the if tells the method to only display if the listing is not any of those folders.

This is not what I want. All of those AND's in the if statement slows things down, and what's worse is that the function I'm using (read()) displays files too.

Might anyone have a method to list folders and only folders - even better would be subdomains if it's possible.

Thanks!
//KiroS
Kiros72 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-15-2006, 11:33 PM Re: Folder Listing Method
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
I took your idea and tried to simplify it. Let me know if it helps (I have not tested it).

PHP Code:
<?php
  
  
// Exclude list of directories not to show
  
$exclude_array = Array (
    
    
'_private''css''images''forums''cgi_bin'
  
);
  
  
$base_dir '/home/public_html/';
  
  
$display = Array();
  
  
$d dir($base_dir);
  while (
$f $d->read()) {
    
    if (!
in_array($f$exclude_array) && is_dir($f)) $display[] = $f;
  }
  
  
// All unmarked directories are now in an array $display
  
?>
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-16-2006, 04:16 AM Re: Folder Listing Method
Kiros72's Avatar
Average Talker

Posts: 18
Name: Kiros
Location: Albany, LA - USA
Trades: 0
Thank you, I appreciate the help, though unfortunately, it's not displaying anything. I've tried changing the base directory and even using it in a literal/concrete way instead of with the variable. No dice. I'm assuming a bug is in the if statement, but it might be in the while... I don't use while's that much :P

Though like I said before, not even a single directory displays.
Kiros72 is offline
Reply With Quote
View Public Profile
 
Old 07-16-2006, 07:00 PM Re: Folder Listing Method
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
The sample above won't display anything, it just puts the results in an array. Try placing print_r($display); at the end to see the array elements.

* Also, you might need to add to the exclude array two more elements "." and ".." to exclude both current directory and parent directory. I finally tested, and it is working.
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-16-2006, 11:26 PM Re: Folder Listing Method
Kiros72's Avatar
Average Talker

Posts: 18
Name: Kiros
Location: Albany, LA - USA
Trades: 0
(accidental early post)

Last edited by Kiros72; 07-16-2006 at 11:30 PM..
Kiros72 is offline
Reply With Quote
View Public Profile
 
Old 07-16-2006, 11:26 PM Re: Folder Listing Method
Kiros72's Avatar
Average Talker

Posts: 18
Name: Kiros
Location: Albany, LA - USA
Trades: 0
(accidental early post)

Last edited by Kiros72; 07-16-2006 at 11:29 PM..
Kiros72 is offline
Reply With Quote
View Public Profile
 
Old 07-16-2006, 11:29 PM Re: Folder Listing Method
Kiros72's Avatar
Average Talker

Posts: 18
Name: Kiros
Location: Albany, LA - USA
Trades: 0
Ok, thank you, I didn't realize that :P

Though are there any functions to return if there is more to the array and if so, move to the next item in the array. I'm thinking about using a for loop, but I'm unfamiliar with arrays in PHP. Are they like C++, where say you would be able to use a for loop as such:
Code:
for ($i = 0; $i < $display.length; $i++)
{
    //some code
    print_r($display[$i]);
    /some more code
}
Sorry, I'm not really sure about the variables with the $'s either
Kiros72 is offline
Reply With Quote
View Public Profile
 
Old 07-16-2006, 11:35 PM Re: Folder Listing Method
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
A simple way to echo links would be like:

(appended to the sample script I show above)

PHP Code:
foreach($display as $value) {
  
  echo 
'<a href="http://www.domain.com/' $value '">' $value '</a><br />';

__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-17-2006, 07:07 PM Re: Folder Listing Method
Super Talker

Posts: 111
Name: Jonathan
Location: Arizona, USA
Trades: 0
I've used this one before: http://evoluted.net/community/code/directorylisting.php
Works pretty good for listing folders (haven't used it to do subdomains). They have a demo on their site.
__________________

Please login or register to view this content. Registration is FREE
- Computer Repair over the internet!
pcoptimized is offline
Reply With Quote
View Public Profile Visit pcoptimized's homepage!
 
Old 07-17-2006, 10:14 PM Re: Folder Listing Method
Kiros72's Avatar
Average Talker

Posts: 18
Name: Kiros
Location: Albany, LA - USA
Trades: 0
Hmmm... This is odd... I have tried your code again, mgraphic, and I'm having a problem.

This code:
PHP Code:
<?php
 
  
// Exclude list of directories not to show
  
$exclude_array = Array (
 
  
'_private''css''images''forums''cgi_bin'
  
);
 
  
$base_dir '/home/kirosite/kirosite.com/html/';
 
  
$display = Array();
 
  
$d dir("/home/kirosite/kirosite.com/html/");
  while (
$f $d->read()) {
 
    if (!
in_array($f$exclude_array) && is_dir($f)) $display[] = $f;
  }
 
  
// All unmarked directories are now in an array $display
 
?>
And this code:
PHP Code:
foreach($display as $value) {
 
  
// Slightly changed anchor code
  
echo '<a href="http://' $value '.mysite.com/">' $value '&apos;s Site!</a><br />';

Is not working together :? I'm using PHP 4.4 by the way.
Does it work for you?

Last edited by Kiros72; 07-17-2006 at 10:16 PM..
Kiros72 is offline
Reply With Quote
View Public Profile
 
Old 07-18-2006, 12:30 PM Re: Folder Listing Method
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
What is it outputting? Can you offer the url of where the script is so I can see the parsed output?
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Old 07-19-2006, 07:22 AM Re: Folder Listing Method
Kiros72's Avatar
Average Talker

Posts: 18
Name: Kiros
Location: Albany, LA - USA
Trades: 0
I have the first, very inefficient and not complete method at the top. After that, I have "-- Another Test --" to show the break and evidently (from looking at the source) that code causes an error because not even the ending body and html tags show up.

The website is: kiros(deletethis)ite.com/(deletethis)first_try_homepage/(deletethis)hostlist.php

I'm sorry about that somewhat messed up link, but I don't want any bots going to the site because it's still in it's very, very early stages and I haven't had any time to really work on it...

Edit:

Hmm... I changed the location to the literal html directory... Now it's working a little bit... I'll keep trying to see if I can get it to work.

Last edited by Kiros72; 07-19-2006 at 07:36 AM..
Kiros72 is offline
Reply With Quote
View Public Profile
 
Old 07-19-2006, 08:21 AM Re: Folder Listing Method
Kiros72's Avatar
Average Talker

Posts: 18
Name: Kiros
Location: Albany, LA - USA
Trades: 0
Small bump... I added a degging section and the PHP body code. Take a look, please... Sorry for the trouble though...
Kiros72 is offline
Reply With Quote
View Public Profile
 
Old 07-22-2006, 02:50 AM Re: Folder Listing Method
Kiros72's Avatar
Average Talker

Posts: 18
Name: Kiros
Location: Albany, LA - USA
Trades: 0
Good news! I've figured out the problem. I do not have any idea why, but it's not accepting the directory I put in, so I'm assuming that it's defaulting to the path of the file. This is not a problem, as the path for the file will move to the root once I complete a basic part of the site.

Thank you a lot mgraphic!
I'm sorry for all the trouble I gave you!

Though there's just one more thing I need to touch on...
Do I have to use the close function after the main code? And if it's not imperative, should I still for security/stability reasons or does it not matter at all? O_o

Last edited by Kiros72; 07-22-2006 at 02:57 AM..
Kiros72 is offline
Reply With Quote
View Public Profile
 
Old 07-22-2006, 02:05 PM Re: Folder Listing Method
mgraphic's Avatar
Truth Seeker

Latest Blog Post:
JAMISONTUNES
Posts: 2,918
Name: Keith Marshall
Location: Connecticut
Trades: 0
Congrads!

Do you mean using the directory closing function? I'm not an expert on this, but I think the benefit of this is to close it to allow for another instance to take place from another request process. I think (maybe) that once a dir is declared open, it is locked.

Please let me know if I'm off base on this...
__________________

<mgraphic /> - I don't have a solution but I admire the problem.
mgraphic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Folder Listing Method
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.40220 seconds with 12 queries