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

    [PHP opendir()] stampa ordinata di cartelle e file

    Salve,
    Sto imparando ad utilizzare le funzioni opendir() e famiglia.
    Ho creato uno script che mi stampa ordinatamente prima tutte le sottodirectory ed in seguito tutti i files presenti in una data directory.
    L'ho testato e funziona solamente se faccio puntare la funzione opendir() alla cartella htdocs di apache (webroot directory).
    Ora mi domando se questo problema può essere dato dai permessi sulle cartelle. Se non è così, mi sapreste dire come mai non funziona tutto come dovrebbe?
    Grazie.
    Ecco lo script
    Codice PHP:
    <?php
    //setto la variabile che serve da parametro all'array $contenuto
    $i=0;
     
    if (
    $handle opendir("./")) {
       echo 
    "Handle della directory: $handle
    \n"
    ;
       echo 
    "[b]Contenuto della dyrectory:[/b]
    \n"
    ;

       
    //leggo il contenuto della directory
       
    while (false !== ($file readdir($handle))) { 
         
    $contenuto[$i]=$file;
         
    $i++;
       }
       
    //stampa le cartelle
       
    for($i=0;$i<=sizeof($contenuto);$i++) {
           if(
    is_dir($contenuto[$i])) {
               print 
    "[b]".$contenuto[$i]."[/b]
    \n"
    ;
           }
       }
       
    //stampa i files
       
    for($i=0;$i<=sizeof($contenuto);$i++) {
           if(!
    is_dir($contenuto[$i])) 
             print 
    $contenuto[$i]."
    \n"
    ;
       }
    closedir($handle);
    }
    ?>
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

  2. #2
    up
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

  3. #3
    davvero nessuno? help please
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

  4. #4
    non c'è nessuno che mi può aiutare?
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

  5. #5
    up!
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

  6. #6
    perchè non inserisci la path correttamente nel is_dir

    $path="./files/prova/";
    if ($handle = opendir($path)) {

    ...

    if(is_dir($path.$contenuto[$i]

  7. #7
    Ora funziona tutta alla perfezione!
    Ti ringrazio ciao
    If today was perfect, there would be no need for tomorrow...
    Live as you want, the wildest way you can, till you're alive!!

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.