icon Get the most out of Surmunity, read our tips here! Need an interesting blog to read? You've got to read the Surpass Blog! | Welcome! Please register to access all of our features.

» Surpass Web Hosting Forums » Discussions » PHP, MySQL » PHP Director Lister

PHP, MySQL General PHP questions. Or go to our PHPsuexec Forum >>

Reply
 
LinkBack Thread Tools Search this Thread Rate Thread
Old September 14th, 2004, 6:18 AM   #1 (permalink)
Registered User
Seasoned Poster
 
Dima's Avatar
 
Joined in Sep 2004
43 posts
Gave thanks: 0
Thanked 0 times
PHP Director Lister

Hi all, I need a directory lister for my site... it would be best if the lister can actually connect to the FTP!


I have a code but it doesnt suit me much because it doesnt show me FILE SIZE and TIME STAMP

Here's the code:

PHP Code:
<?php
$ip     
'ftp.domain.com';
$user   'access[at]domain.com';
$pass   'password';
$port   '21';
$path   "";

function 
listDir($dir,$ftp)
{
    echo 
$dir;
    
ftp_pasv($ftp,true);
    
ftp_chdir($ftp,$dir);
    
$list ftp_rawlist($ftp,".");
    foreach(
$list as $item)
    {
        
ereg("([-d])([rwxst-]{9}).* ([0-9]*) ([a-zA-Z]+[0-9: ]* [0-9]{2}:?[0-9]{2}) (.+)"$item$matches);   
             
        if (
$matches[1] == 'd'
        {   
            
listDir($dir.'/'.$matches[5],$ftp);
        }
        else
        {
echo 
'<dd>'.$matches[5].'</dd>';
        }
        
flush();
    }
}

$ftp ftp_connect($ip,$port);
ftp_login($ftp,$user,$pass);

echo 
'<dl>';
listDir($path,$ftp);
echo 
'</dl>';
?>
Thank you in advance
__________________

Last edited by Dima; September 14th, 2004 at 6:20 AM.
Dima is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 14th, 2004, 8:18 AM   #2 (permalink)
minor deity
Super #1
 
Bigjohn's Avatar
 
Joined in Apr 2004
Lives in Georgia
Hosted on XEON
7,338 posts
Gave thanks: 23
Thanked 93 times
The script you have is pulling ftp_rawlist, so it should have what you want in there. Have a look at the PHP.NET page for the FTP functions:

http://us4.php.net/manual/en/function.ftp-rawlist.php
__________________
Proud to be a Surmunity Mod!
XEON PASS60 PASS61
Make a fundamental difference!
My Sites:
Curious about Brewing Beer? Join the community!
>>>>> Some Change is GOOD! Keep your paycheck! Support the Fair Tax
Get into an Art museum
Victorian London
It's your brain -ON WEB - mybrainhost.com (under development)
What SHOULD Government do? Much Less than it Does!
Bigjohn is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 14th, 2004, 8:50 AM   #3 (permalink)
Registered User
Seasoned Poster
 
Dima's Avatar
 
Joined in Sep 2004
43 posts
Gave thanks: 0
Thanked 0 times
thanks for that... im stilling figuring out how to add the file size thing
__________________
Dima is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 17th, 2004, 10:23 AM   #4 (permalink)
Registered User
Seasoned Poster
 
Dima's Avatar
 
Joined in Sep 2004
43 posts
Gave thanks: 0
Thanked 0 times
anyone pleasE?
__________________
Dima is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old September 18th, 2004, 12:43 AM   #5 (permalink)
Surpass Fan
Seasoned Poster
 
Joined in Aug 2004
Lives in North Carolina, USA
Hosted on Pass11
46 posts
Gave thanks: 0
Thanked 0 times
I've made a dirlist script that simply reads from the directory the script sits in(easily modified to view any directory). I've never messed with the FTP functions.

I think i used scandir (or equivelent) function to just pull a directory listing into an array, and stepped through the array, checking each "filename" to see if it was a directory or filename, and was able to easily access the modified time and filesize with the set of filesystem functions.

If you can't get the info you need from the FTP listings, try resolving a path to whatever file/subdir you're looping on and use the PHP filesystem functions instead. (filesize, filemtime)

http://www.php.net/filesystem
__________________
All your base are belong to us.
AngryPeasant is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Rate This Thread
Rate This Thread:

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

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