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
Retrieved list of files/dir how to display alphabetically...
Old 02-09-2008, 03:49 PM Retrieved list of files/dir how to display alphabetically...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Hey all,

okay i got my simple file management script going and here the chunk which retrieves all the files and directories and makes my thing...

PHP Code:
function file_extension($file)
{
    
$path_info pathinfo($file);
    return 
$path_info['extension'];
}
 
// This is the directory to list files for.
if(isset($_GET['dir']))
{
$theDirectory            DOC_ROOT."/".$_GET['dir'].'/';
}
else {
$theDirectory            DOC_ROOT."/";
}
// Do you want to show directories? change to false to hide directories.
$listDirectories    true;
if(
is_dir($theDirectory))
{
    echo 
"<table border='1'><tr><td>Name</td><td>Type</td><td>Size</td><td>CMOD</td><td>ext</td><td>Edit</td></tr>";
 echo 
'<tr><td><a href="file_manager.php">Home</a></td><td>-</td><td>-</td><td>-</td><td>-</td><td>-</td></tr>';
    
$dir opendir($theDirectory);
    while(
false !== ($file readdir($dir)))
    {
        
$type    filetype($theDirectory ."/"$file);
        if(
$listDirectories || $type != "dir")
        {
   if(isset(
$_GET['dir']))
   {
   
$cur_dir $_GET['dir'].'/';
   }
            echo 
"<tr><td><a href='?dir=".$cur_dir.$file."'>" $file "</a></td>";
            echo 
"<td>" $type "</td>";
            echo 
"<td>";
      echo 
filesize($theDirectory.$file);
            echo 
"</td><td>";
            echo 
substr(sprintf('%o'fileperms($theDirectory.$file)), -4);
   echo 
"</td><td>";
 
            if(
$type == "file")
   {
   echo 
file_extension($file);
   echo 
'</td>';
 
    
$editables = array('php','txt','phps','htm','html','js','css','htaccess');
    foreach(
$editables as $allowed_ext)
    { 
     if(
file_extension($cur_dir.$file) == $allowed_ext)
     {
     echo 
'<td>';
     echo 
'<a href="file_manager.php?do=edit&file='.$cur_dir.$file.'">Edit</a>';
     echo 
'</td>';
     }
    }
// Emd Foreach
   
}//End if file is file.
   
else {
   echo 
'-</td><td>-</td>';//Shows in Edit collum and EXT
   
}//End else file
   
echo '</tr>';
        }
    }
// End while.
    
closedir($dir);
    echo 
"</table>";
}
else
{
    echo 
$theDirectory " is not a directory";

but how can i make the files show alphabetically (and if possible have directories at the top and files after them, like in most OS's)

Thanks al, and as always TP if you can help
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
 
Register now for full access!
Old 02-09-2008, 04:48 PM Re: Retrieved list of files/dir how to display alphabetically...
rogem002's Avatar
PHP Chap

Posts: 843
Name: Mike
Location: United Kingdom
Trades: 0
I think an array sort is what you need:
http://uk.php.net/manual/en/function...-multisort.php
http://uk.php.net/manual/en/function.asort.php

Though, I'm afraid I can only guess you need to put it about:
PHP Code:
    $dir opendir($theDirectory);
    while(
false !== ($file readdir($dir))) 
For example:
PHP Code:
    $dir opendir($theDirectory);
asort($dir);
    while(
false !== ($file readdir($dir))) 
__________________
My Blog/Site:
Please login or register to view this content. Registration is FREE

Last edited by rogem002; 02-09-2008 at 04:53 PM..
rogem002 is offline
Reply With Quote
View Public Profile Visit rogem002's homepage!
 
Old 02-09-2008, 04:57 PM Re: Retrieved list of files/dir how to display alphabetically...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
had a go with it and it seems that it isnt a array

i used:
PHP Code:
while(false !== array_multisort(($file readdir($dir)),SORT_DESC,SORT_STRING)) 
and i got the error: Warning: array_multisort() [function.array-multisort]: Argument #1 is expected to be an array or a sort flag in /home/ukcalm/public_html/admin/file_manager.php on line 69

So erm any idea?
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-10-2008, 01:47 AM Re: Retrieved list of files/dir how to display alphabetically...
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Store all of your strings in an array and then sort that array.
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 02-10-2008, 05:27 AM Re: Retrieved list of files/dir how to display alphabetically...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
i tried that using this block:
PHP Code:
    $dir opendir($theDirectory);
 
 while (
false !== ($dir_files readdir($dir))) {
    
$files[] = $dir_files;
 }
    while(
array_multisort($files,SORT_DESC,SORT_STRING))
    {
        
$type    filetype($theDirectory ."/"$file);
        if(
$listDirectories || $type != "dir")
        {
   if(isset(
$_GET['dir']))
   {
   
$cur_dir $_GET['dir'].'/'
but now i cant load the page, it takes ages uses up a TON of memory and CPU for ie and then crashes and freezes the system
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-10-2008, 12:55 PM Re: Retrieved list of files/dir how to display alphabetically...
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
hello!

don't know if this would help?

http://www.tizag.com/mysqlTutorial/mysqlorderby.php

i am a newbie so just trying to help

shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-10-2008, 01:36 PM Re: Retrieved list of files/dir how to display alphabetically...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
nope thats SQL, i know how to do that
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-10-2008, 01:42 PM Re: Retrieved list of files/dir how to display alphabetically...
Sharon_leic's Avatar
Super Talker

Posts: 115
Name: Sharon
Location: Leicester, uk
Trades: 0
Quote:
Originally Posted by dansgalaxy View Post
nope thats SQL, i know how to do that
oops, sorry, i just seen the word sort
Shaz x
__________________
mysql_connect("localhost", "brain", "sharon") or die(mysql_error());
mysql error: brain doesn't exist!
Sharon_leic is offline
Reply With Quote
View Public Profile
 
Old 02-10-2008, 02:09 PM Re: Retrieved list of files/dir how to display alphabetically...
maxxximus's Avatar
Extreme Talker

Posts: 219
Name: Rob
Location: UK
Trades: 0
You should be using the new scandir function (php5). http://uk3.php.net/scandir

Scandir returns an array not a string. You can then use the sort($array) functions http://uk2.php.net/sort.

Then you can loop through the array with a foreach loop.
maxxximus is offline
Reply With Quote
View Public Profile
 
Old 02-10-2008, 05:33 PM Re: Retrieved list of files/dir how to display alphabetically...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Thanks Maxxximus works a treat, if only i could put the folders before the normal files this would be perfect

P.S i tried but cant give u no more TP
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-11-2008, 07:18 PM Re: Retrieved list of files/dir how to display alphabetically...
starlord's Avatar
Extreme Talker

Posts: 209
Name: Darran
Trades: 5
I know your doing your own code but did you look at autoindex?

http://autoindex.sourceforge.net/

demo : http://autoindex.sourceforge.net/demo/

I have used this in the past and it just works ... unlike so many things these days

Starlord
__________________
##
Please login or register to view this content. Registration is FREE
##
Please login or register to view this content. Registration is FREE
##

Please login or register to view this content. Registration is FREE
starlord is offline
Reply With Quote
View Public Profile
 
Old 02-12-2008, 11:09 AM Re: Retrieved list of files/dir how to display alphabetically...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Just downloading it, looks ok, dont seem to have any other functins than display but hopefully i can figure out how to seperate the folders from the files from the code
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-12-2008, 11:14 AM Re: Retrieved list of files/dir how to display alphabetically...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
wow theres alot of of stuff in that script, seems way too overly complicated.
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Old 02-12-2008, 01:39 PM Re: Retrieved list of files/dir how to display alphabetically...
starlord's Avatar
Extreme Talker

Posts: 209
Name: Darran
Trades: 5
Quote:
Originally Posted by dansgalaxy View Post
wow theres alot of of stuff in that script, seems way too overly complicated.

I'm still very much a newbie where PHP is concerned and have no problem using other (OS) scripts to do the job ...

that said yes theres a lot of un-needed and repeated stuff in there ... but when I just want a pretty directory listing it does the job ... complete with pretty icon which my downloaders seem to like

Starlord
__________________
##
Please login or register to view this content. Registration is FREE
##
Please login or register to view this content. Registration is FREE
##

Please login or register to view this content. Registration is FREE
starlord is offline
Reply With Quote
View Public Profile
 
Old 02-12-2008, 02:02 PM Re: Retrieved list of files/dir how to display alphabetically...
dansgalaxy's Avatar
Defies a Status

Posts: 6,521
Name: Dan
Location: Swindon
Trades: 0
Lol, im not saying its not good, im just going for as simple as possible and just non pretty and functional have most of the file manager done
__________________
Discounted Web Hosting With XDnet!
>> Get 25% of hosting~ Promo: Webmaster-talk <<

Please login or register to view this content. Registration is FREE
dansgalaxy is offline
Reply With Quote
View Public Profile Visit dansgalaxy's homepage!
 
Reply     « Reply to Retrieved list of files/dir how to display alphabetically...
 

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 1.01312 seconds with 12 queries