Avatar billede tras Juniormester
21. marts 2006 - 08:17 Der er 1 løsning

Hvordan får jeg mapper så php filer osv til at stå først i div?

Jeg kan bare ikke få mapperne til at være først og så php filerne osv. Hvordan gør jeg.

<?
                            $path= "./";
                            if ($handle = opendir($path)) {
                                while (false !== ($file = readdir($handle))) {
                                    if ($file != "." && $file != "..") {
                                        if(is_dir("$path".$file)){
                                            echo "<div style=\"padding-left: 2px; margin: 0px;\"  >";
                                            echo "|-<b><a href=\"#\" onClick=pokazi(\"$file\")>$file</a></b><br />\n";
                                            $id="$file";
                                            dirT("$path$file/",$id);
                                        }else{
                                            if(strstr(strtolower($file),".php")){
                                            ?><img src="images/icons/php.gif"><a href="?open=<? echo "$file\n"; ?>"><? echo "$file<br />\n";?></a><?
                                            }elseif(strstr(strtolower($file),".css")){
                                            ?><img src="images/icons/php.gif"><a href="?open=<? echo "$file\n"; ?>"><? echo "$file<br />\n";?></a><?
                                            }elseif(strstr(strtolower($file),".asp")){
                                            ?><img src="images/icons/php.gif"><a href="?open=<? echo "$file\n"; ?>"><? echo "$file<br />\n";?></a><?
                                            }elseif(strstr(strtolower($file),".html")){
                                            ?><img src="images/icons/html.gif"><a href="?open=<? echo "$file\n"; ?>"><? echo "$file<br />\n";?></a><?
                                            }elseif(strstr(strtolower($file),".jpg")){
                                            ?><img src="images/icons/jpg.gif"><a href="?open=<? echo "$file\n"; ?>"><? echo "$file<br />\n";?></a><?
                                            }elseif(strstr(strtolower($file),".gif")){
                                            ?><img src="images/icons/gif.gif"><a href="?open=<? echo "$file\n"; ?>"><? echo "$file<br />\n";?></a><?
                                            }elseif(strstr(strtolower($file),".txt")){
                                            ?><img src="images/icons/txt.gif"><a href="?open=<? echo "$file\n"; ?>"><? echo "$file<br />\n";?></a><?
                                            }
                                        }
                                    }
                                }
                                echo "</div>";
                                closedir($handle);
                            }
                            function dirT($path,$id){
                            echo "<div style=\"padding-left: 2px; margin: 2px; display:none \" id=\"$id\">";
                                if ($handle = opendir($path)) {
                                    while (false !== ($file = readdir($handle))) {
                                        if ($file != "." && $file != "..") {
                                            if(is_dir("$path".$file)){
                                                echo "<div style=\"padding-left: 10px; margin: 2px; \" >";
                                                echo "|-<a href=\"#\" onClick=pokazi(\"$file\")>$file</a><br />\n";
                                                $id="$file";
                                                dirT("$path$file/",$id);
                                            }else{
                                                ?><a href="?open=<? echo "$path";?><? echo "$file"; ?>"><? echo "&nbsp;--$file<br />\n";?></a><?
                                            }
                                        }
                                    }
                                    echo "</div>";
                                    closedir($handle);
                                }
                                echo "</div>";
                            }
                        ?>
Avatar billede tras Juniormester
21. marts 2006 - 09:46 #1
Well det eneste jeg kan finde på er dette men der stiller den ikke mine filer efter endelse.

<?php
                        # Do we have a path? if not, it's the current directory
                        $path = $_GET["path"];
                        if( !isset( $path ) || $path == "" )  {
                            $path = ".";
                        }
                        # Print out for navigation
                        print "Current path: <b>" . $path . "</b><br />";
                        # Initialise list arrays, directories and files separately and array counters for them
                        $d_arr = array(); $d = 0;
                        $f_arr = array(); $f = 0;
                        # Open possibly available directory
                        if( is_dir( $path ) ) {
                            if( $handle = opendir( $path ) ) {
                                    while( false !== ( $file = readdir( $handle ) ) ) {
                                        # Make sure we don't push parental directories or dotfiles (unix) into the arrays
                                        if( $file != "." && $file != ".." && $file[0] != "." ) {
                                                if( is_dir( $path . "/" . $file ) )
                                                    # Create array for directories
                                                    $d_arr[$d++] = $file;
                                                else
                                                    # Create array for files
                                                    $f_arr[$f++] = $file;
                                        }
                                    }
                            }
                        }
                        # Wrap things up if we're in a directory
                        if( is_dir( $handle ) ) closedir( $handle );
                        # Sort and reset the arrays
                        asort( $d_arr ); reset( $d_arr );
                        asort( $f_arr ); reset( $f_arr );
                        # Print a parent directory link
                        $d_prev = substr( $path, 0, ( strrpos( dirname( $path . "/." ), "/" ) ) );
                        print "<a href=\"?path=" . $d_prev . "\"> Go Back </a><br />\n";
                   
                        # Print the directory list
                        for( $i=0; $i < count( $d_arr ); $i++ ) {
                            # Print with query string
                            print "<a href=\"?path=" . $path . "/" . $d_arr[$i] . "\">" . $d_arr[$i] . "</a>/<br />\n";
                        }
                        # Print file list
                        for( $i=0; $i < count( $f_arr ); $i++ ) {
                            # Only print path and filename
                            if(strstr(strtolower($f_arr[$i]),".php")){
                            ?><img src="images/icons/php.gif"><? print "<a href=\"?open=" . $path . "/" . $f_arr[$i] . "\"> " . $f_arr[$i] . "</a>";
                            }elseif(strstr(strtolower($f_arr[$i]),".css")){
                            ?><img src="images/icons/php.gif"><? print "<a href=\"?open=" . $path . "/" . $f_arr[$i] . "\"> " . $f_arr[$i] . "</a>";
                            }elseif(strstr(strtolower($f_arr[$i]),".asp")){
                            ?><img src="images/icons/php.gif"><? print "<a href=\"?open=" . $path . "/" . $f_arr[$i] . "\"> " . $f_arr[$i] . "</a>";
                            }elseif(strstr(strtolower($f_arr[$i]),".html")){
                            ?><img src="images/icons/html.gif"><? print "<a href=\"?open=" . $path . "/" . $f_arr[$i] . "\"> " . $f_arr[$i] . "</a>";
                            }elseif(strstr(strtolower($f_arr[$i]),".txt")){
                            ?><img src="images/icons/txt.gif"><? print "<a href=\"?open=" . $path . "/" . $f_arr[$i] . "\"> " . $f_arr[$i] . "</a>";
                            }elseif(strstr(strtolower($f_arr[$i]),".jpg")){
                            ?><img src="images/icons/jpg.gif"><? print "<a href=\"" . $path . "/" . $f_arr[$i] . "\"> " . $f_arr[$i] . "</a>";
                            }elseif(strstr(strtolower($f_arr[$i]),".gif")){
                            ?><img src="images/icons/gif.gif"><? print "<a href=\"" . $path . "/" . $f_arr[$i] . "\"> " . $f_arr[$i] . "</a>";
                            }elseif(strstr(strtolower($f_arr[$i]),".ico")){
                            ?><img src="images/icons/unknown.gif"><? print "<a href=\"" . $path . "/" . $f_arr[$i] . "\"> " . $f_arr[$i] . "</a>";
                            }
                            # We may want a file size. NOTE: needs $path to stat
                            if( filesize( $path . "/" . $f_arr[$i] ) >= 1024 ) {
                                    # Size in kilobytes
                                    print " " . round( filesize( $path . "/" . $f_arr[$i] ) / 1024, 1 ) . " KB<br />\n";
                            } elseif( filesize( $path . "/" . $f_arr[$i] ) >= 1048576 ) {
                                    # Size in megabytes
                                    print " " . round( filesize( $path . "/" . $f_arr[$i] ) / 1024 / 1024, 1 ) . " MB<br />\n";
                            } else {
                                    # Size in bytes
                                    print " " . filesize( $path . "/" . $f_arr[$i] ) . " B<br />\n";
                            }
                        }
                    ?>
Avatar billede Ny bruger Nybegynder

Din løsning...

Tilladte BB-code-tags: [b]fed[/b] [i]kursiv[/i] [u]understreget[/u] Web- og emailadresser omdannes automatisk til links. Der sættes "nofollow" på alle links.

Loading billede Opret Preview
Kategori
Vi tilbyder markedets bedste kurser inden for webudvikling

Log ind eller opret profil

Hov!

For at kunne deltage på Computerworld Eksperten skal du være logget ind.

Det er heldigvis nemt at oprette en bruger: Det tager to minutter og du kan vælge at bruge enten e-mail, Facebook eller Google som login.

Du kan også logge ind via nedenstående tjenester