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

    Problema con filesize e filetype

    Salve, stavo provando questo codice per ottenere nome, tipo di file, dimensione del file e link di tutti i file in una cartella, però ho un problema: filesize e filetype non funzionano, o meglio non appaiono. Ho provato anche ad usare stat ma niente..


    Codice PHP:
    <style type="text/css">
    th, td {
    width: 25%;
    }

    th {
    background: #FFE4C4;
    }

    table {
    width: 60%;
    margin: auto;
    }
    </style>
    <table border="1">
       <thead>
              <tr>
                     <th>Nome File</th>
                     <th>Tipo di File</th>
                     <th>Dimensione File</th>
                     <th>Link File</th>
              </tr>
       </thead>
       <tbody>
    <?php

    $cartella 
    opendir('./images');
    while (
    $file readdir($cartella)) {
    $file_array[] = $file;
    sort($file_array);
    }
    foreach (
    $file_array as $file) {
    if ( 
    $file == ".." || $file == ".") {
    continue;
    }
    echo 
    '<tr>
              <td>'
    .$file.'</td>
              <td>'
    .filetype($file).'</td>
              <td>'
    .filesize($file).'</td>
              <td>[url="images/'
    .$file.'"]Clicca qui[/url]</td>
              </tr>'
    ;
    }
    ?> 
       </tbody>
    </table>
    Codice PHP:
    <style type="text/css">
    th, td {
    width: 25%;
    }

    th {
    background: #FFE4C4;
    }

    table {
    width: 60%;
    margin: auto;
    }
    </style>
    <table border="1">
       <thead>
              <tr>
                     <th>Nome File</th>
                     <th>Tipo di File</th>
                     <th>Dimensione File</th>
                     <th>Link File</th>
              </tr>
       </thead>
       <tbody>
    <?php

    $cartella 
    opendir('./images');
    while (
    $file readdir($cartella)) {
    $file_array[] = $file;
    sort($file_array);
    }
    foreach (
    $file_array as $file) {
    if ( 
    $file == ".." || $file == ".") {
    continue;
    }
    $stat stat($file);
    echo 
    '<tr>
              <td>'
    .$file.'</td>
              <td>'
    .$stat['rdev'].'</td>
              <td>'
    .$stat['size'].'</td>
              <td>[url="images/'
    .$file.'"]Clicca qui[/url]</td>
              </tr>'
    ;
    }
    ?> 
       </tbody>
    </table>
    Da cosa dipende il problema? Il bello è che nel secondo nemmeno da errore per gli apici..
    Social Network in costruzione.. Misto tra Twitter e Facebook.. Twitbook o facetter?

  2. #2
    Il problema e' che readdir() restituisce il semplice NOME del file, non il percorso completo, quindi quando esegui qualche funzione su quel file devi aggiungere la directory in cui si trova per ottenere il path esatto.

  3. #3
    Grazie mille, ora ho risolto, ma è normale che filetype dica "file" a tutti i file? (cioè sono tutte immagini..)
    Social Network in costruzione.. Misto tra Twitter e Facebook.. Twitbook o facetter?

  4. #4
    Stando al manuale e' normalissimo:
    Return Values

    Returns the type of the file. Possible values are fifo, char, dir, block, link, file, socket and unknown.

  5. #5
    Sì stavo leggendo anche io ora, sai se c'è un modo per scoprire proprio il tipo di file? (immagine jpeg, document html ecc.)

    O mi devo creare uno script per trovare le estensioni?
    Social Network in costruzione.. Misto tra Twitter e Facebook.. Twitbook o facetter?

  6. #6
    Ti conviene guardare l'estensione, ma non e' necessario creare uno script visto che c'e' una funzione apposta: http://uk.php.net/pathinfo

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