Visualizzazione dei risultati da 1 a 2 su 2
  1. #1
    Utente di HTML.it
    Registrato dal
    Sep 2007
    Messaggi
    183

    Visualizzare elenco file PDF

    Salve a tutti,
    premetto che con il php ho problei

    Sarò breve:

    vorrei creare una pagina in php che visualizza un elenco di file PDF contenuti in una cartella,
    l'elenco deve semplicemente una lista con il nome del file ed il logo in pdf,
    se il file esiste lo visualizza altrimenti no ( ) poi ad ogni nome deve corrispondere il link
    per il download del file.

    NON posso usare MySQL

    Domanda:
    Come posso fare???

    Ho iniziato a scrivere questo ma non credo sia corretto.!!!
    <?php
    $fs = "CARTELLA_CONTENENTE_FILE_PDF"; -----> mi serve del cdice per identificare la presenza del file pdf ed il nome
    $fb = "prova.pdf";
    if( file_exists( $fs ) )
    echo 'NOME_DEL_FILE';
    ?>

    :master:

  2. #2
    Utente di HTML.it
    Registrato dal
    Sep 2007
    Messaggi
    183
    Mi Autorispondo

    ==============================
    FILE php N°1
    ==============================
    <?php

    // --------------------------------------------------------------------
    // ----------------- Here there be dragons ----------------------------
    // --------------------------------------------------------------------

    // constants for DFileList::getList()

    define('DFL_DIRECTORY', 1); // show directories
    define('DFL_DIRFIRST', 2); // show directories at the beginning of the list

    define('DFL_DEFAULT_TEMPLATE',
    '&raquo; %%name%% is a %%type%% of size %%size%% bytes
    ');

    // define fnmatch is the function is missing (on windows or php < 4.3.0)
    if (!function_exists('fnmatch')) {
    function fnmatch($pattern, $string) {
    return @preg_match(
    '/^' . strtr(addcslashes($pattern, '/\\.+^$(){}=!<>|'),
    array('*' => '.*', '?' => '.?')) . '$/i', $string
    );
    }
    }


    // ------------------ DFileList class ---------------------------------
    class DFileList {

    var $aDirTypes = array();
    var $aTypes = array();
    var $aTemplates = array();
    var $aHide = array();
    var $aTransform = array();
    var $aProcess = array();

    var $pRoot = '';

    var $iFileCount = 0;
    var $iDirCount = 0;
    var $iFileSize = 0;


    // ----> DFileList() --------------------------------------------------
    function DFileList($path = '') {
    $this->pRoot = $path;
    }


    // ----> setType() ----------------------------------------------------
    function setType($type, $patterns = array(), $directory = 0) {
    if (!is_array($patterns))
    $patterns = array($patterns);
    if (count($patterns) == 0)
    return false;

    if ($directory)
    $list =& $this->aDirTypes;
    else
    $list =& $this->aTypes;

    $first = array_shift($patterns);
    $list[$first] = $type;
    $count = 1;

    foreach($patterns as $pattern) {
    $list[$pattern] =& $list[$first];
    $count += 1;
    }

    return $count;
    }


    // ----> setHidden() --------------------------------------------------
    function setHidden($patterns = array()) {
    if (!is_array($patterns))
    $patterns = array($patterns);
    if (count($patterns) == 0)
    return false;

    $count = 0;

    foreach($patterns as $pattern) {
    $this->aHide[] = $pattern;
    $count += 1;
    }

    return $count;
    }


    // ----> getList() ----------------------------------------------------
    function getList($flags = 0) {
    $totals = array(
    'dir' => 0,
    'files' => 0,
    'size' => 0
    );
    $files = array();
    $dirs = array();

    $list = glob($this->pRoot . '*');

    foreach($list as $file) {
    $rec = array(
    'fullname' => $file,
    'name' => basename($file),
    'size' => filesize($file),
    'time' => filemtime($file),
    'perms' => fileperms($file),
    'type' => ''
    );

    $toHide = false;
    foreach($this->aHide as $pattern)
    if (fnmatch($pattern, $rec['name'])) {
    $toHide = true;
    break;
    }
    if ($toHide) continue;

    if (filetype($file) == 'dir') {

    foreach($this->aDirTypes as $pattern => $type)
    if (fnmatch($pattern, $rec['name'])) {
    $rec['type'] = $type;
    break;
    }

    if ($flags & DFL_DIRECTORY) {
    $totals['dir'] += 1;

    if ($flags & DFL_DIRFIRST)
    $dirs[] = $rec;
    else
    $files[] = $rec;
    }

    } else {

    foreach($this->aTypes as $pattern => $type)
    if (fnmatch($pattern, $rec['name'])) {
    $rec['type'] = $type;
    break;
    }

    $files[] = $rec;
    $totals['files'] += 1;
    $totals['size'] += $rec['size'];

    }

    }

    if ($flags & DFL_DIRFIRST)
    $files = array_merge($dirs, $files);

    return array(
    'total' => $totals,
    'files' => $files
    );
    }


    // ----> setTransform() -----------------------------------------------
    function setTransform($elem, $function) {
    if (!function_exists($function))
    return false;

    $this->aTransform[$elem] = $function;
    return true;
    }

    // ----> setProcess() -------------------------------------------------
    function setProcess($type, $function) {
    if (!function_exists($function))
    return false;

    $this->aProcess[$type] = $function;
    return true;
    }


    // ----> setTemplate() ------------------------------------------------
    function setTemplate($templates, $template = '') {
    $count = 0;

    if (is_array($templates)) {

    if (count($templates) == 0)
    return false;

    $count = 0;
    foreach($templates as $type => $template) {
    $this->aTemplates[$type] = $template;
    $count += 1;
    }

    return $count;

    } else {
    if ($template == '') {
    $this->aTemplates['*'] = $templates;
    } else {
    $this->aTemplates[$templates] = $template;
    }

    return 1;
    }

    }


    // ----> renderList() -------------------------------------------------
    function renderList($list = array()) {
    if (!isset($list['files']))
    return false;

    $output = '';
    foreach($list['files'] as $file)
    if (is_array($file)) {

    $elem = DFL_DEFAULT_TEMPLATE;

    foreach($this->aTemplates as $pattern => $template)
    if (fnmatch($pattern, $file['type'])) {
    $elem = $template;
    break;
    }

    foreach($this->aProcess as $pattern => $process)
    if (fnmatch($pattern, $file['type'])) {
    eval($process . '($file);');
    break;
    }

    foreach($file as $key => $value) {
    if (isset($this->aTransform[$key]))
    $value = call_user_func($this->aTransform[$key], $value, $file['fullname']);
    $elem = str_replace("%%$key%%", $value, $elem);
    }

    $output .= $elem;
    }

    return $output;

    }

    }

    ?>






    ==============================
    FILE php N°2
    ==============================
    <?php


    require_once('dFileList.inc.php');

    $l = new DFileList();

    $l->setHidden( array('index.php') );

    $l->setType('acrobat', '*.pdf' );

    $l->setType('unknown', '*');
    $l->setType('folder', '*', DFL_DIRECTORY);



    function makeSize($size) {
    $units = array('B','KB','MB','GB','TB');
    $u = 0;
    while ( (round($size / 1024) > 0) && ($u < 4) ) {
    $size = $size / 1024;
    $u++;
    }
    return (round($size,2) . " " . $units[$u]);
    }

    function makeTime($time) {
    return date('d-M-Y h:i', $time);
    }

    $l->setTransform('size', 'makeSize');
    $l->setTransform('time', 'makeTime');


    $l->setTemplate( array(

    'folder' => '<tr>
    <td>[img]icons-type/%%type%%.png[/img]</td>
    <td>%%name%%</td>
    <td></td>
    <td></td>
    </tr> ',

    '*' => '<tr>
    <td>[img]icons-type/%%type%%.png[/img]</td>
    <td>%%name%%</td>
    <td>%%time%%</td>
    <td>%%size%%</td>
    </tr> '

    ) );


    $elenco = $l->getList( DFL_DIRECTORY | DFL_DIRFIRST );

    echo " <table> <thead>\n <tr><td id=\"c-type\">Tipo</td><td id=\"c-name\">Nome</td><td id=\"c-time\">Ultima modifica</td><td id=\"c-size\">Dimensione</td></tr>\n </thead> <tbody>\n ";
    echo $l->renderList( $elenco );
    echo "\n </tbody> </table>\n";

    echo "\n <p id=\"summary\">Totale: " . makeSize($elenco['total']['size']);
    echo " ({$elenco['total']['dir']} directory e {$elenco['total']['files']} file)</p>";

    ?>

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.