Visualizzazione risultati 1 fino 3 di 3

Discussione: Problema con filesize e filetype

  1. #1
    Guest

    Predefinito 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><a href="images/'
    .$file.'" target="_blank">Clicca qui</a></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><a href="images/'
    .$file.'" target="_blank">Clicca qui</a></td>
    </tr>'
    ;
    }
    ?>
    </tbody>
    </table>

  2. #2
    L'avatar di dreadnaut
    dreadnaut non è connesso Super Moderatore
    Data registrazione
    22-02-2004
    Messaggi
    6,269

    Predefinito

    glob glob glob glob

    Per il problema delle due funzioni invece, esse ritornano false se c'è stato un errore. Quindi devi controllare eventuali messaggi di errore con error_reporting(E_ALL) oppure error_get_last().
    Ultima modifica di dreadnaut : 17-06-2011 alle ore 23.03.42

  3. #3
    Guest

    Predefinito

    >_> Comunque ho risolto, avevo messo solo il nome del file e non la path, mentre quelle due funzioni la richiedevano

Regole di scrittura

  • Non puoi creare nuove discussioni
  • Non puoi rispondere ai messaggi
  • Non puoi inserire allegati.
  • Non puoi modificare i tuoi messaggi
  •