Visualizzazione dei risultati da 1 a 5 su 5
  1. #1

    [PHP] Script elenco file

    Ciao a tutti, sono nuovo e mi chiamo Davide...
    Il problema è questo:
    - L'username è minuscolo invece io voglio che sia maiuscolo *solo l'iniziale* (prova -> Prova)
    - La data è errata
    - La dimensione pure
    - Anche il tipo di file...
    - Vengono mostrati i dati solo x 1 file!!!
    Codice PHP:
    <?
    session_start
    ();
    if(!
    session_is_registered(myusername)){
    header("location:login2.php");
    }
    ?>
    <?php
    include ("/membri/sim/file/dw/config.php"); // Dati + Con x accedere al DB!
    ?>
    <?
    # configuration
    $show_path 1# show local path
    $show_dotdirs 0# show and '..'

    $path substr($SCRIPT_FILENAME0strrpos($SCRIPT_FILENAME"/")+1);
    ?>
    <html>
    <head>
    <title>@@@SIMUPLOADER@@@</title>
    <style type="text/css">
    <!--
    a, a:active {text-decoration: none; color: blue;}
    a:visited {color: #48468F;}
    a:hover, a:focus {text-decoration: underline; color: red;}
    body {background-color: #F5F5F5;}
    h2 {margin-bottom: 12px;}
    table {margin-left: 12px;}
    th, td { font-family: "Courier New", Courier, monospace; font-size: 10pt; text-align: left;}
    th { font-weight: bold; padding-right: 14px; padding-bottom: 3px;}
    td {padding-right: 14px;}
    td.s, th.s {text-align: right;}
    div.list { background-color: white; border-top: 1px solid #646464; border-bottom: 1px solid #646464; padding-top: 10px; padding-bottom: 14px;}
    div.foot { font-family: "Courier New", Courier, monospace; font-size: 10pt; color: #787878; padding-top: 4px;}
    username:first-letter {font-family: "Courier New", Courier, monospace; font-size: 10pt; color: #787878; padding-top: 4px; font-variant: small-caps;}
    /*body, th, td { background-color: #ffffff;
    font-family: verdana, arial;
    }

    a:link { color: #666666;
    text-decoration: underline;
    }
    a:visited { color: #444444;
    text-decoration: underline;
    }
    a:hover { color: #666666;
    text-decoration: none;
    }
    a:active { color: #660000;
    text-decoration: none;
    }

    table.files { background-color: #222222;
    border: 2px solid #cccccc;
    border-spacing: 1px;
    width: 480px;
    }
    th.files { background-color: #4466aa;
    color: #ffffff;
    font-size: 11pt;
    font-weight: bold;
    text-align: left;
    padding: 2px;
    }
    td.files { background-color: #eeeeee;
    color: #666666;
    font-size: 9pt;
    font-weight: normal;
    padding: 6px;
    }*/
    -->
    </style>
    </head>
    <body>
    <h2><?php if ($show_path == 1) { echo "Posizione: "; echo $path; } else { echo "Contenuto della Directory..."; } ?></h2>
    <div class="list">
    <table summary="Directory Listing" cellpadding="0" cellspacing="0">
    <thead><tr><th class="n">Nome</th><th class="m">Ultima Modifica</th><th class="s">
    Peso</th><th class="t">Tipo</th></tr></thead>

    <tbody>
    <tr><td class="n">[url=""]Cartella Precedente[/url]/</td><td class="m">- </td><td class="s">- </td><td class="t">
    Cartella</td></tr>
    <tr><td class="n"><?php
    $dirs 
    = array();
    $files = array();

    $dir dir($path);
    while (
    $entry $dir->read()) {
    if (
    $entry != "." && substr($entry, -4) != ".php") {
    if (
    is_dir($entry)) {
    if (
    $entry != ".." || $show_dotdirs){
    $dirs[] = $entry;
    }
    } else {
    $files[] = $entry;
    }
    }
    }
    $dir->close();

    sort($dirs);
    foreach (
    $dirs as $dir) {
    echo 
    '[url="' $dir '"]' $dir "[/url]
    \n"
    ;
    }

    sort($files);
    foreach (
    $files as $file) {
    echo 
    '<a href="' $file '">' $file "
    \n"
    ;
    }
    ?></td><td class="m"><?php

    $filedata 
    $file;

    echo 
    date ("m/j/Y h:i"filemtime($filedata));
    /*// il file da verificare.
    $modifica = $file;
    // variabile che prende l’informazione.
    $last_time_modified = filemtime($modifica);
    // formatta la data
    $last_mod = date("m/j/Y h:i", $last_time_modified);
    print $last_mod;*/
    ?></td><td class="s"><?php

    $filesize 
    $file;

    echo 
    sizeof($filesize);
    /*
    function filesize_format($file) {
    if($file < pow(1024, 1)) return $file. "B";
    elseif($file < pow(1024, 2)) return round($file/pow(1024, 1), 3)."Kb";
    elseif($file < pow(1024, 3)) return round($file/pow(1024, 2), 3)."Mb";
    elseif($file < pow(1024, 4)) return round($file/pow(1024, 3), 3)."Gb";
    }
    echo filesize_format($file);*/
    /*$strimmagine = file_get_contents($file);
    $dimensione = strlen($strimmagine);
    echo ("$dimensione");*/
    ?></td><td class="t"><?php

    $filetipo 
    $file;

    echo 
    filetype($filetipo); // tipo del file
    ?></td></tr>
    </tbody>
    </table>
    </div>
    <div class="foot">[i]Ciao <span class="username"><?php
    /*
    $query = "SELECT username FROM admin";
    $result = mysql_query($query);

    while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { }*/
    echo $myusername;
    ?></span>
    ... [url="logout.php"]Logout[/url][/i]</div>
    </body>
    </html>
    Url: http://www.sim.altervista.org/file/dw/
    Username: prova
    Password: prova
    Grazie.Ciao Davide!
    Davide {Webmaster}

  2. #2
    Beh.... hai messo tutto il codice ma le tue richieste sono molto stringate.

    Ad ogni modo vediamo di risolvere passo passo.

    1)
    L'username è minuscolo invece io voglio che sia maiuscolo *solo l'iniziale* (prova -> Prova)
    C'è una funzione apposita ucfirst().

    Codice PHP:
    $var "prova";
    $var ucfirst($var);
    echo 
    $var// restituisce: Prova 

    2)
    - La data è errata - La dimensione pure - Anche il tipo di file...
    Cosa intendi per errata?
    Per il tipo, mi sembra che siano tutte GIF, la dimensione non l'ho controllata, la data mi sembra OK!

    3)
    - Vengono mostrati i dati solo x 1 file!!!
    Fammici lavorare un attimo sopra, perché secondo me hai sbagliato il ciclo.

    <ALCIO />
    Per cortesia: no PVT Tecnici
    ******* LINKS *******
    SRL
    MetalWave

  3. #3
    Grazie..i problemi li ho risolti tutti tranne 2:
    La dimensione spunta sempre 1...ma 1 cosa?
    Sono andato su:
    http://it.php.net/function.filesize
    e ho preso questo:
    Codice PHP:
    function filesize_format($filesize) {
            if(
    $filesize pow(10241)) return       $filesize.                 " Bytes";
        elseif(
    $filesize pow(10242)) return round($filesize/pow(10241), 3)." KiB";
        elseif(
    $filesize pow(10243)) return round($filesize/pow(10242), 3)." MiB";
        elseif(
    $filesize pow(10244)) return round($filesize/pow(10243), 3)." GiB";
        elseif(
    $filesize pow(10245)) return round($filesize/pow(10244), 3)." TiB";
        elseif(
    $filesize pow(10246)) return round($filesize/pow(10245), 3)." PiB";
        elseif(
    $filesize pow(10247)) return round($filesize/pow(10246), 3)." EiB";
        elseif(
    $filesize pow(10248)) return round($filesize/pow(10247), 3)." ZiB";
        else                             return 
    round($filesize/pow(10248), 3)." YiB"; } 
    Modificato viene così:
    Codice PHP:
       if($file!="." && $file!=".." && substr($file, -4) != ".php")

       function 
    filesize_format($file) {
            if(
    $file pow(10241)) return       $file.                 " Bytes";
        elseif(
    $file pow(10242)) return round($file/pow(10241), 3)." KiB";
        elseif(
    $file pow(10243)) return round($file/pow(10242), 3)." MiB";
        elseif(
    $file pow(10244)) return round($file/pow(10243), 3)." GiB";
        elseif(
    $file pow(10245)) return round($file/pow(10244), 3)." TiB";
        elseif(
    $file pow(10246)) return round($file/pow(10245), 3)." PiB";
        elseif(
    $file pow(10247)) return round($file/pow(10246), 3)." EiB";
        elseif(
    $file pow(10248)) return round($file/pow(10247), 3)." ZiB";
        else                         return 
    round($file/pow(10248), 3)." YiB"
        }
        echo 
    filesize_format(); 
    In pratica $file è la variabile che mostra il file..
    Dopo il 2 è questo:
    Il tipo funziona! Ma non funziona come vorrei io..
    mi spunta "file" o "dir" (dir se è una cartella, mentre file qualsiasi cosa!)
    Io vorrei che fosse tipo così:
    .png = Immagine PNG
    .doc = Documento Word
    .zip = Archivio Zip
    $cartella = Cartella
    .$ = File (quando non è inserito mostra "File)
    Grazie 1000..Ciao Davide!
    Ah: http://wwww.sim.altervista.org/file/dw/listfile.php

    Edit:
    Da errore alla linea 66 che sarebbe questa:
    Codice PHP:
       function filesize_format($file) { 
    Ed ecco tutto il pezzo che mostra la dimensione:
    Codice PHP:
    <?php

    echo "<td class=\"s\">";

       if(
    $file!="." && $file!=".." && substr($file, -4) != ".php")

       function 
    filesize_format($file) {
            if(
    $file pow(10241)) return       $file.                 " Bytes";
        elseif(
    $file pow(10242)) return round($file/pow(10241), 3)." KiB";
        elseif(
    $file pow(10243)) return round($file/pow(10242), 3)." MiB";
        elseif(
    $file pow(10244)) return round($file/pow(10243), 3)." GiB";
        elseif(
    $file pow(10245)) return round($file/pow(10244), 3)." TiB";
        elseif(
    $file pow(10246)) return round($file/pow(10245), 3)." PiB";
        elseif(
    $file pow(10247)) return round($file/pow(10246), 3)." EiB";
        elseif(
    $file pow(10248)) return round($file/pow(10247), 3)." ZiB";
        else                         return 
    round($file/pow(10248), 3)." YiB"
        }
        echo 
    filesize_format();
       
       
    /*$filesize = $file;
    echo sizeof($filesize);*/

          
    echo "</td>";
    ?>
    Ri-Edit:
    Ho pulito il codice da commenti, spazi ecc...
    Ma anche se cambia il n° (73) la linea di PHP è sempre quella (ho controllato )
    Davide {Webmaster}

  4. #4
    ...nessuno?
    Davide {Webmaster}

  5. #5
    Originariamente inviato da davide00951p
    ...nessuno?
    Davide {Webmaster}

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.