Visualizzazione dei risultati da 1 a 6 su 6

Discussione: Gestione File

  1. #1
    Utente di HTML.it
    Registrato dal
    May 2004
    Messaggi
    83

    Gestione File

    Ciao a tutti scusate la domanda cretina!! ma conosco poco di php e volevo chiedere se era possibile trovare o creare uno script per la gestione di file. vi illustro precisamente quello che cerco.

    Ho una cartella sul mio web dove inserisco dei file in pdf tramite ftp, ora vorrei che lo script che cerco, mi crei un elenco di tutti i file che si trovano nella cartella e li pubblichi su una pagina!!!

    Grazie in anticipo

  2. #2
    Utente bannato
    Registrato dal
    Apr 2004
    Messaggi
    1,392
    NUOVO Regolamento + PILLOLE trattate [LEGGERE PRIMA DI POSTARE]

    [PILLOLA] lettura di una directory

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2004
    Messaggi
    83
    Grazie per la info!!!
    ho provato ad applicare quello che mi dice la pillola, ma non ho risultati!!!!
    ho creato la mia pagina index.php con il seguente codice!!!


    <?php function dirtree($path){
    /**
    * author: kuarl<grivier@animeterminal.it>
    * date: 26-08-2002
    */
    $fd = opendir($path);
    while($file = readdir($fd)){
    if($file != '.' && $file != '..'){
    $ris[count($ris)] = $path."/".$file;
    if(is_dir($ris[count($ris)-1])){
    unset($ris[count($ris)-1]);
    $ris = array_merge($ris, dirtree($path."/".$file));
    }
    }
    }
    // questo pezzo serve x le directory vuote
    if(!@sort($ris)){
    $ris[0] = $path;
    }
    //------------------------------------------------
    closedir($fd);
    return $ris;
    }
    ?>

    Ma nulla di fatto!!!

    Originariamente inviato da PaTeR
    NUOVO Regolamento + PILLOLE trattate [LEGGERE PRIMA DI POSTARE]

    [PILLOLA] lettura di una directory

  4. #4
    è una funzione che in $ris ti da l'elenco che cerchi, ovviamente non te lo stampa, non ti guarda quali sono e di che tipo i file, ti da solamente l'elenco di una directory nella variabile $ris.

    tutto dipende da quello che devi farci ora con questo elenco.


    se li vuoi stampare devi scorrere l'array risultato e fare l'echo di ogni elemento.


  5. #5
    Utente di HTML.it
    Registrato dal
    May 2004
    Messaggi
    83
    Nella pillola ho trovato questo!!
    <?php
    $nuovariga = 1;
    $numerofoto = 0;
    if ($dirfoto = opendir('/home/virtual/site1/fst/var/www/html/'.$struttura))
    // il percorso è da adattare, la variabile $struttura indica il nome della directory
    {
    while (false !== ($foto = readdir($dirfoto)))
    {
    if ($foto != "." && $foto != "..") // tolgo i puntini scomodi
    {
    $numerofoto = $numerofoto +1;
    print ("<a href=\"".$struttura."/".$foto."\" border=\"0\" target=\"_blank\"><img src=\"http://www.dominio.it/images/standard/foto_ico.png\" border=\"0\">".$numerofoto."</a>
    "); // a me sta bene chiamare le foto solo col numero, altri magari vogliono utilizzare altri nomi, facile modificare
    if ($nuovariga !== 4) // il numero indica quante colonne deve avere la tabella
    {
    print ("</td><td>");
    $nuovariga = $nuovariga+1;
    }
    else
    {
    print ("</td></tr><tr><td>");
    $nuovariga = '1';
    }
    }

    }
    closedir($dirfoto);

    }
    ?>
    e malgrado la mia ignoranza sono riuscito a far funzionare!!! ma come posso mettere la lista dei file in almeno due colonne invece che una e mattergli invece che un numero sequenziale....
    il nome del file e l'ultima modifica??


    Originariamente inviato da Tymba
    è una funzione che in $ris ti da l'elenco che cerchi, ovviamente non te lo stampa, non ti guarda quali sono e di che tipo i file, ti da solamente l'elenco di una directory nella variabile $ris.

    tutto dipende da quello che devi farci ora con questo elenco.


    se li vuoi stampare devi scorrere l'array risultato e fare l'echo di ogni elemento.


  6. #6
    Utente di HTML.it
    Registrato dal
    May 2004
    Messaggi
    83

    Ho trovato la soluzione!!!

    Allora ho trovato questo codice che va molto bene!

    <?php

    $thisFileName = "index.php";
    $thisDirectoryPath = $REQUEST_URI;

    $thisServerName = $SERVER_NAME;

    $thisPageFilesDir = "indexerfiles/";

    $thisPageCssFile= $thisPageFilesDir."dirindexer.css";

    $fileImgProps = array('filepath' => $thisPageFilesDir."file.gif", 'height' => '18', 'width' => '18');
    $dirImageProps = array('filepath' => $thisPageFilesDir."dir.gif", 'height' => '13', 'width' => '13');
    $bulletImgsArr = array('fileImg' => $fileImgProps, 'dirImg' => $dirImageProps);

    #---------------------------------------------------
    /*
    Add the name of this file and the namess of the files and dirs used with it to arrays. When the files and directories
    are read in, files and dirs in these 2 arrays will not by listed or counted when this page is viewed. If there are any other files
    other than those actually used by this page that you'd rather not have so readily available to others through this page, you can
    add them into these arrays
    */
    #---------------------------------------------------


    $dontListFiles = array($thisFileName, $bulletImgsArr['dirImg']['filepath'], $bulletImgsArr['fileImg']['filepath'], $thisPageCssFile);
    $dontListDirs = array($thisPageFilesDir, "cgi-bin", "indexerfiles");

    function getThisDirName($url)
    {
    #---------------------------------------------------
    /*
    getThisDirName : Accepts the path to the directory either in the form of $REQUEST_URI
    or a string value and pulls out the directory name
    */
    #---------------------------------------------------
    $afterCutOne = substr($url, 0, strrpos($url, "/"));
    $afterCutTwo = substr($afterCutOne, strrpos($afterCutOne, "/") - strlen($afterCutOne) + 1);
    return $afterCutTwo;
    }

    #---------------------------------------------------
    /*
    isort and isortMultiD are 2 sorting functions used to add pseudo
    alphabetical order to the list of directory names and file names
    */
    #---------------------------------------------------

    function isort($a,$b)
    {
    #---------------------------------------------------
    /*
    isort :

    ord (http://www.php.net/manual/en/function.ord.php) returns the ASCII value of the first character in a string (the ASCII value of a capital letter is different from that of a lower case letter)

    strtolower (http://www.php.net/manual/en/function.strtolower.php) converts all uppercase chrs in a string to lowercase

    This function compares the lower-cased first letter in one string to that in another. We'll use it to compare directory names
    */
    #---------------------------------------------------
    if(ord(strtolower($a)) == ord(strtolower($b))) return 0;
    return (ord(strtolower($a))< ord(strtolower($b))) ? -1: 1;
    }

    function isortMultiD($a,$b)
    {
    #---------------------------------------------------
    /*
    isortMultiD : This function basically is the same as issort, except that it runs the comparison between the 2nd row in each array, then the first.
    We'll be using it to sort the filenames, where the j in $filesArr[i][j] is the extension (bmp, gif, jpg, etc) and the i is the name itself.
    */
    #---------------------------------------------------
    if(ord(strtolower($a[count($a) - 1])) == ord(strtolower($b[count ($b) - 1])))
    {
    if(ord(strtolower($a[0])) == ord(strtolower($b[0]))) return 0;
    return (ord(strtolower($a[0]))< ord(strtolower($b[0]))) ? -1: 1;
    }
    return (ord(strtolower($a[count ($a) - 1])) < ord(strtolower($b[count ($b)]))) ? -1: 1;
    }

    function indexdirThisDir()
    {
    #---------------------------------------------------
    /*
    indexdirThisDir : This function scours through the current directory (regardless of which directory u specify via the getThisDirName call)
    and makes a list of directories and does the same for files, first by their extensions
    and then by their names. Remember that since it's only alphabetical on the first char php and phtml or php3 and php files will be jumbled together,
    as will html and htm (the same logic holds for file names).
    */
    #---------------------------------------------------
    global $bulletImgsArr;
    global $dontListFiles;
    global $dontListDirs;

    $numHiddenDirs = 0;
    $numHiddenFiles = 0;

    $dirsArr = array();
    $filesArr = array();

    $this_dir_handle=opendir('.'); # get a handle on the current directory
    while (false!==($fileORdir = readdir($this_dir_handle)))
    {
    if ($fileORdir != "." && $fileORdir != "..")
    {
    if(is_dir($fileORdir)== false)
    {
    $thisFileNoShow = 0;
    for ($i = 0; $i < count($dontListFiles); $i++)
    {
    if($fileORdir == $dontListFiles[$i])
    {
    $thisFileNoShow = 1;
    $numHiddenFiles++;
    break;
    }
    }
    if($thisFileNoShow == 0)
    {
    $fileNameAndextensionArr = explode(".", $fileORdir);
    array_push ($filesArr, $fileNameAndextensionArr);
    }
    }
    else
    {
    $thisDirNoShow = 0;
    for ($i = 0; $i < count($dontListDirs); $i++)
    {
    if($fileORdir == $dontListDirs[$i])
    {
    $thisDirNoShow = 1;
    $numHiddenDirs++;
    break;
    }
    }
    if($thisDirNoShow == 0)
    {
    array_push ($dirsArr, $fileORdir);
    }
    }
    }
    }
    closedir($this_dir_handle);

    $listingHTML .= "<div id=\"thisdircontains\">Questa Directory Contiene: ".count($dirsArr)." Sottodirectory e ".count($filesArr)." files </div>\n";

    usort($dirsArr, 'isort');
    usort($filesArr, 'isortMultiD');

    $listingHTML .="\n<div id=\"dirslist\">\n";
    for ($i = 0; $i < count($dirsArr); $i++)
    {
    $listingHTML .= "<a href target =\"".$dirsArr[$i]."/\" class =\"dirs\"><img src=\"".$bulletImgsArr['dirImg']['filepath']."\" height=\"".$bulletImgsArr['dirImg']['height']."\" width=\"".$bulletImgsArr['dirImg']['width']."\" alt=\"file\" />".$dirsArr[$i]." </a>
    \n";
    }
    $listingHTML .="</div>\n\n";

    $listingHTML .="<div id=\"fileslist\">\n<table>\n<tr><td>Batch Previste</td>";
    for ($i = 0; $i < count($filesArr); $i++)
    {
    $filesArr[$i] = join (".", $filesArr[$i]);
    $fileStats = stat($filesArr[$i]);
    ##$fileSizeInKb = round(($fileStats[7]/1024),2);
    ##$fileLastMod = date("H : i M dS Y", $fileStats[9]);
    $listingHTML .= "<tr><td> <a href =\"".$filesArr[$i]."\" target = blank class =\"files\"><img src=\"".$bulletImgsArr['fileImg']['filepath']. "\" height=\"".$bulletImgsArr['fileImg']['height']."\" width=\"".$bulletImgsArr['fileImg']['width']."\" alt=\"file\" />".$filesArr[$i]."</a></td><td class=\"filedetails\">".$fileSizeInKb."</td><td class=\"filedetails\">".$fileLastMod." </td></tr> \n";
    }
    $listingHTML .='</table></div>';

    return $listingHTML;
    }

    $thisDirName = getThisDirName($thisDirectoryPath);
    $listingHTMLstring = indexdirThisDir();

    header( "Content-type: text/html" );

    print ("
    <!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">
    <html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\" >
    <head>
    <title>index of $thisDirName</title>
    <link rel=\"stylesheet\" type=\"text/css\" href=\"$thisPageCssFile\" />
    </head>

    <body>
    <h1>$thisDirName</h1>
    $listingHTMLstring



    </body>
    </html>");

    ?>

    Ora l'unico problema è questo, dato che la pagina php l'ho messa centralmente tra due frame... ho visto che per qualche secondo la pagina rimane bianca!! evidentemente piu file ci sono nella cartella piu ci mette!!! vorrei sapere da qualche anima santa come posso far apparire in php la scritta..... caricamento pagina!!!!

    Grazie!!!

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 © 2024 vBulletin Solutions, Inc. All rights reserved.