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

    visualizzare directory con esclusione

    Salve,
    ho necessità di listare il contenuto di una cartella.
    Ho trovato questo script che fa esattamente quello di cui avevo bisogno.
    basta prenderlo e metterlo nella cartella interessata.
    Come faccio ad escludere dall'elenco la visualizzazione dei file .htaccess e .htpasswd che per forza di cose mi trovo ad avere nella cartella?
    Grazie.
    [PHP<?
    #######[[[ SCROLL TO BOTTOM OF THIS FILE TO CHANGE THE TEMPLATE ]]]######

    /**
    * PHPDL - PHP Directory Lister
    *
    * {@link http://greg-j.com/some-url PHDL} is an all-in-one directory listing script.
    * What sets it apart from other scripts of similar nature is that it includes all
    * its resources in itself in base64 format, allowing PHPDL to deliver an asthetic
    * and interactive experience without the need for any external files.
    *
    * @name PHPDL
    * @version 2.0
    * @author Greg Johnson <greg@greg-j.com>
    * @link http://greg-j.com/some-url
    * @license http://creativecommons.org/licenses/by-sa/3.0/us/
    */


    /** ------------------[ SETTINGS ]
    *
    * @var $ext_filter Excludes file types from being downloaded. If you have PHPDL
    * in a directory with other php files you do not want people to
    * be able to see the source of, do not change this.
    *
    * Adding the value '*' will disable the feature altogether.
    *
    * @var $sort Set the default sorting properties. The first array sets the
    * initial sort column and order whereas the second array sets
    * the sort column and order for items that match the first array's
    * paramters
    *
    * @var $vWidth Width of the popup video player
    * @var $vHeight Height of the popup video player
    */
    $ext_filter = array('php', 'php4', 'php5');
    $sort = array(
    array('key'=>'lname', 'sort'=>'asc'),
    array('key'=>'size', 'sort'=>'asc')
    );
    $vWidth = '800';
    $vHeight = '450';


    /** ---------------------[ EMBEDED IMAGES ]
    * @desc Are we requesting a file type icon? If so, deliver the appropriate
    * image for the file extension being requested.
    */
    if(isset($_GET['image']))
    {
    // Accomidate uppercase & lowercase file extensions
    $image = strtolower($_GET['image']);
    // Set filetypes (most of this list is from http://www.filezed.com)
    $filetype = array(
    'text' => array('doc', 'docx', 'txt', 'rtf', 'odf', 'text', 'nfo'),
    'audio' => array('aac', 'mp3', 'wav', 'wma', 'm4p'),
    'graphic' => array('ai', 'bmp', 'eps', 'gif', 'ico', 'jpg', 'jpeg', 'png', 'psd', 'psp', 'raw', 'tga', 'tif', 'tiff'),
    'video' => array('mv4', 'bup', 'mkv', 'ifo', 'flv', 'vob', '3g2', 'bik', 'xvid', 'divx', 'wmv', 'avi', '3gp', 'mp4', 'mov', '3gpp', '3gp2', 'swf', 'mpg', 'mpeg'),
    'archive' => array('7z', 'dmg', 'rar', 'sit', 'zip', 'bzip', 'gz', 'tar'),
    'app' => array('exe', 'msi', 'mse', 'bat'),
    'script' => array('js', 'html', 'htm', 'xhtml', 'jsp', 'asp', 'aspx', 'php', 'xml', 'css')
    );

    // Set the mimetype and cache the image for a year so we don't have to call them again.
    header("Content-type: image/png");
    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 60 * 60 *24 * 365) . ' GMT');

    // Deliver the correct image ...
    if($image == '.') echo base64_decode('');
    elseif($image == 'pdf') echo base64_decode('');
    elseif($image == 'download') echo base64_decode('');
    elseif(in_array($image, $filetype['text'])) echo base64_decode('');
    elseif(in_array($image, $filetype['audio'])) echo base64_decode('');
    elseif(in_array($image, $filetype['graphic'])) echo base64_decode('');
    elseif(in_array($image, $filetype['video'])) echo base64_decode('');
    elseif(in_array($image, $filetype['archive'])) echo base64_decode('');
    elseif(in_array($image, $filetype['app'])) echo base64_decode('');
    elseif(in_array($image, $filetype['script'])) echo base64_decode('');
    else echo base64_decode('');

    // Exit this script when the correct image has been served
    exit();
    }


    /** ------------------[ FORCE FILE DOWNLOAD ]
    * @desc Process the request for direct file download based on the
    * value(s) in the $ext_filter setting.
    */
    if(isset($_GET['download']) && !in_array('*', $ext_filter))
    {
    // Get the file to download
    $file = $_GET['download'];

    // Make sure the file is delivered properly.
    if(ini_get('zlib.output_compression'))
    {
    ini_set('zlib.output_compression', 'off');
    }

    // Prevent abuse
    $file = str_replace(array("/", ".."), "", $file);

    // Get file extension
    $file_extension = strtolower(substr(strrchr($file,"."),1));

    if (in_array($file_extension, $ext_filter))
    {
    exit('File Type Invalid');
    }
    elseif(!file_exists($file))
    {
    exit('File Does Not Exist');
    }

    // Special delivery
    header("Pragma: public");
    header("Expires: 0");
    header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
    header("Cache-Control: private",false);
    header("Content-type: application/force-download");
    header("Content-Disposition: attachment; filename=\"".basename($file)."\";" );
    header("Content-Transfer-Encoding: binary");
    header("Content-Length: ".filesize($file));
    readfile("$file");
    exit();
    }



    /** ----------------------------[ GET EMBEDED RESOURCE ]
    * @desc Get embeded resources
    * jQuery & Thickbox could have easily been put in the <html>, but this keeps it smaller,
    * cacheable and the code more manageable.
    */
    if(isset($_GET['resource']))
    {
    $resource = $_GET['resource'];

    header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 60 * 60 *24 * 365) . ' GMT');

    if($resource == 'thickbox.css')
    {
    header("Content-type: text/css");
    echo base64_decode('');
    exit();
    }
    elseif($resource == 'jquery.packed.js')
    {
    header("Content-type: application/x-javascript");
    echo base64_decode('');
    exit();
    }
    elseif($resource == 'thickbox.packed.js')
    {
    header("Content-type: application/x-javascript");
    echo base64_decode('');
    exit();
    }
    elseif($resource == 'player_mp3_mini.swf')
    {
    header("Content-type: application/x-shockwave-flash");
    echo base64_decode('');
    exit();
    }
    elseif($resource == 'player.swf')
    {
    header("Content-type: application/x-shockwave-flash");
    echo base64_decode('');
    exit();
    }
    elseif($resource == 'loadingAnimation.gif')
    {
    header("Content-type: image/gif");
    echo base64_decode('');
    exit();
    }
    }


    /** -------------------------------[ READ DIRECTORY ]
    * @desc This is where all the magic happens. We read the current directory and
    * build an array of images and folders to list.
    */
    // Get this folder and files name.
    $this_script = basename(__FILE__);
    $this_folder = str_replace('/'.$this_script, '', $_SERVER['SCRIPT_NAME']);

    // Declare vars used beyond this point.
    $file_list = array();
    $folder_list = array();
    $total_size = 0;

    // Open the current directory...
    if ($handle = opendir('.'))
    {
    // ...start scanning through it.
    while (false !== ($file = readdir($handle)))
    {
    // Make sure we don't list this folder, file or their links.
    if ($file != "." && $file != ".." && $file != $this_script)
    {
    // Get file info.
    $stat = stat($file); // ... slow, but faster than using filemtime() & filesize() instead.
    $info = pathinfo($file);

    // Organize file info.
    $item['name'] = $info['filename'];
    $item['lname'] = strtolower($info['filename']);
    $item['ext'] = $info['extension'];
    if($info['extension'] == '') $item['ext'] = '.';
    $item['bytes'] = $stat['size'];
    $item['size'] = bytes_to_string($stat['size'], 2);
    $item['mtime'] = $stat['mtime'];

    // Build links. Add interactivity. Be cool.
    if(in_array($item['ext'], array('jpg', 'jpeg', 'png', 'gif', 'bmp'))) // thickbox for images
    {
    $item['link'] = ''.$item['name'].'.'.$item['ext'].'';
    }
    elseif(in_array($item['ext'], array('mov', 'mpg', 'mpeg'))) // thickbox for quicktime
    {
    $item['link'] = ''.$item['name'].'.'.$item['ext'].'';
    }
    elseif($item['ext'] == 'flv') // thickbox for flv's'
    {
    $item['link'] = ''.$item['name'].'.'.$item['ext'].'';
    }
    elseif($item['ext'] == 'mp3') // thickbox for mp3's'
    {
    $item['link'] = ''.$item['name'].'.'.$item['ext'].'';
    }
    else // standard link
    {
    $item['link'] = ''.$item['name'].'.'.$item['ext'].'';
    }

    // Add files to the file list...
    if($info['extension'] != '')
    {
    array_push($file_list, $item);
    }
    // ...and folders to the folder list.
    else
    {
    array_push($folder_list, $item);
    }
    // Clear stat() cache to free up memory (not really needed).
    clearstatcache();
    // Add this items file size to this folders total size
    $total_size += $item['bytes'];
    }
    }
    // Close the directory when finished.
    closedir($handle);
    }
    // Sort folder list.
    if($folder_list)
    $folder_list = php_multisort($folder_list, $sort);
    // Sort file list.
    if($file_list)
    $file_list = php_multisort($file_list, $sort);
    // Calculate the total folder size
    if($file_list && $folder_list)
    $total_size = bytes_to_string($total_size, 2);


    /** -------------------[ FUNCTIONS ]
    * @desc Define functions used in this script
    */


    /**
    * @author http://us.php.net/manual/en/function...sort.php#83117
    * @desc Sorts a multidimensional array akin to sorting an SQL result
    */
    function php_multisort($data,$keys)
    {
    foreach ($data as $key => $row)
    {
    foreach ($keys as $k)
    {
    $cols[$k['key']][$key] = $row[$k['key']];
    }
    }
    $idkeys = array_keys($data);
    $i=0;
    foreach ($keys as $k)
    {
    if($i>0){$sort.=',';}
    $sort.='$cols['.$k['key'].']';
    if($k['sort']){$sort.=',SORT_'.strtoupper($k['sort']);}
    if($k['type']){$sort.=',SORT_'.strtoupper($k['type']);}
    $i++;
    }
    $sort .= ',$idkeys';
    $sort = 'array_multisort('.$sort.');';
    eval($sort);
    foreach($idkeys as $idkey)
    {
    $result[$idkey]=$data[$idkey];
    }
    return $result;
    }

    /**
    * @author http://us3.php.net/manual/en/functio...size.php#84652
    * @desc Gets a filesize in bytes, returns a string representation
    * of that file in an easily readable format.
    */
    function bytes_to_string($size, $precision = 0) {
    $sizes = array('YB', 'ZB', 'EB', 'PB', 'TB', 'GB', 'MB', 'KB', 'Bytes');
    $total = count($sizes);
    while($total-- && $size > 1024) $size /= 1024;
    $return['num'] = round($size, $precision);
    $return['str'] = $sizes[$total];
    return $return;
    }

    /**
    * @author http://us.php.net/manual/en/function.time.php#71342
    * @desc Returns the time between now and timestamp provided
    */
    function time_ago($timestamp, $recursive = 0)
    {
    $current_time = time();
    $difference = $current_time - $timestamp;
    $periods = array("second", "minute", "hour", "day", "week", "month", "year", "decade");
    $lengths = array(1, 60, 3600, 86400, 604800, 2630880, 31570560, 315705600);
    for ($val = sizeof($lengths) - 1; ($val >= 0) && (($number = $difference / $lengths[$val]) <= 1); $val--);
    if ($val < 0) $val = 0;
    $new_time = $current_time - ($difference % $lengths[$val]);
    $number = floor($number);
    if($number != 1)
    {
    $periods[$val] .= "s";
    }
    $text = sprintf("%d %s ", $number, $periods[$val]);

    if (($recursive == 1) && ($val >= 1) && (($current_time - $new_time) > 0))
    {
    $text .= time_ago($new_time);
    }
    return $text;
    }

    /**
    * @desc Used to allow download/show download icon based on disallowed file types
    * @todo extend this function to base a files download elegibility on its relation
    * to ini_get('memory_limit') && memory_get_usage() so files that are too
    * big to process are not attempted.
    */
    function isDL($true, $false = '')
    {
    global $ext_filter;

    if(!in_array('*', $ext_filter))
    {
    return $true;
    }
    else
    {
    return $false;
    }
    }

    [/PHP]
    Cristina Pr

  2. #2
    Utente di HTML.it L'avatar di kodode
    Registrato dal
    Sep 2002
    Messaggi
    1,896
    prova a sostituire questa riga
    Codice PHP:
    if ($file != "." && $file != ".." && $file != $this_script
    Codice PHP:

    con
    if ($file != "." && $file != ".." && $file != $this_script && $file != ".htaccess" && $file != ".htpasswd" 

  3. #3
    Bravo kodode
    Funziona.

    Grazie
    Ciao
    Cristina Pr

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.