Помогите вывести массив PHP

kuzmit42

Постоялец
Регистрация
9 Янв 2013
Сообщения
132
Реакции
31
Хочу сделать листинг файлов папки. Есть скрипт который выводит все данные по файлам, имя, размер, дата, и т.д.
Но выводятся они в мативе, и я не могу привести их в нормальный вид. чтобы сделать таблицу.
Знания пхп очень слабые с массивами вообще не знаком.
Помогите пожалуйста что куда вставить чтобы ланные выводились в табличке. <tr><td></td></tr>

Скрипт прикрепил.
Путь к папке листинга вставляется в самом низу строкой "print_r(dir_list('W:/backup/file/')); "
PHP:
<?php

        function permission($filename)
        {
            $perms = fileperms($filename);

            if     (($perms & 0xC000) == 0xC000) { $info = 's'; }
            elseif (($perms & 0xA000) == 0xA000) { $info = 'l'; }
            elseif (($perms & 0x8000) == 0x8000) { $info = '-'; }
            elseif (($perms & 0x6000) == 0x6000) { $info = 'b'; }
            elseif (($perms & 0x4000) == 0x4000) { $info = 'd'; }
            elseif (($perms & 0x2000) == 0x2000) { $info = 'c'; }
            elseif (($perms & 0x1000) == 0x1000) { $info = 'p'; }
            else                                 { $info = 'u'; }

            // владелец
            $info .= (($perms & 0x0100) ? 'r' : '-');
            $info .= (($perms & 0x0080) ? 'w' : '-');
            $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));

            // группа
            $info .= (($perms & 0x0020) ? 'r' : '-');
            $info .= (($perms & 0x0010) ? 'w' : '-');
            $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));

            // все
            $info .= (($perms & 0x0004) ? 'r' : '-');
            $info .= (($perms & 0x0002) ? 'w' : '-');
            $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));

            return $info;
        }

        function dir_list($dir)
        {
            if ($dir[strlen($dir)-1] != '/') $dir .= '/';

            if (!is_dir($dir)) return array();

            $dir_handle  = opendir($dir);
            $dir_objects = array();
            while ($object = readdir($dir_handle))
                if (!in_array($object, array('.','..')))
                {  
                    /*
                    print "
                    <tr>
                        <td>тип</td>
                        <td class=\"title\">
                            <a href=\"../../backup/file/$object\">$object</a>
                        </td>
                        <td>тут размер KB</td>
                        <td>тут права</td>
                        <td>тут дата</td>
                    </tr>
                    <!--<a href=\"../../backup/file/$file\">$file</a> <br />-->";
                    */
                  
                    $filename    = $dir . $object;
                  
                    $file_object = array(
                                             '<p>',
                                            'Имя:' => $object,
                                            'Размер:' => filesize($filename),
                                            'Права' => permission($filename),
                                            'Тип:' => filetype($filename),
                                            'Дата' => date("m.d.Y", filemtime($filename)),
                                            '</p>'
                                        );
                                      
                    $dir_objects[] = $file_object;
                }

            return $dir_objects;
        }

?>
<?php
        print_r(dir_list('W:/backup/file/'));
?>
 
Скрипт для проверки прав, ему уже лет 6 или 7:
Для просмотра ссылки Войди или Зарегистрируйся
У нас в движке он хранится в папке /tools — там разные инструменты для случаев когда вдруг сайт не работает.
В строчках 61-64 вставьте свои папки, на которых должны быть права записи, и он их проверит и выведет красным если что не так.
Рекурсивно:)
 
человек просил таблицу....
PHP:
<?php

function permission($filename)
{
    $perms = fileperms($filename);

    if     (($perms & 0xC000) == 0xC000) { $info = 's'; }
    elseif (($perms & 0xA000) == 0xA000) { $info = 'l'; }
    elseif (($perms & 0x8000) == 0x8000) { $info = '-'; }
    elseif (($perms & 0x6000) == 0x6000) { $info = 'b'; }
    elseif (($perms & 0x4000) == 0x4000) { $info = 'd'; }
    elseif (($perms & 0x2000) == 0x2000) { $info = 'c'; }
    elseif (($perms & 0x1000) == 0x1000) { $info = 'p'; }
    else                                 { $info = 'u'; }

    // владелец
    $info .= (($perms & 0x0100) ? 'r' : '-');
    $info .= (($perms & 0x0080) ? 'w' : '-');
    $info .= (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x' ) : (($perms & 0x0800) ? 'S' : '-'));

    // группа
    $info .= (($perms & 0x0020) ? 'r' : '-');
    $info .= (($perms & 0x0010) ? 'w' : '-');
    $info .= (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x' ) : (($perms & 0x0400) ? 'S' : '-'));

    // все
    $info .= (($perms & 0x0004) ? 'r' : '-');
    $info .= (($perms & 0x0002) ? 'w' : '-');
    $info .= (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x' ) : (($perms & 0x0200) ? 'T' : '-'));

    return $info;
}

function dir_list($dir)
{
    if ($dir[strlen($dir)-1] != '/') $dir .= '/';

    if (!is_dir($dir)) return array();

    $dir_handle  = opendir($dir);
    $dir_objects = array();
    while ($object = readdir($dir_handle))
        if (!in_array($object, array('.','..')))
        {
        

            $filename    = $dir . $object;

            $file_object = array(
                'name' => $object,
                'size' => filesize($filename),
                'rights' => permission($filename),
                'type' => filetype($filename),
                'date' => date("m.d.Y", filemtime($filename)),
            );

            $dir_objects[] = $file_object;
        }

    return $dir_objects;
}

?>
<?php
$files = dir_list('D:\usr\home\Dropbox\Winginx\home\illine\procms\\');
echo "
            <table border=1><tr>
                <td>1 колонка</td>
                <td>2 колонка</td>
                <td>3 колонка</td>
                <td>4 колонка</td>
                <td>5 колонка</td>
            </tr>";

foreach ($files as $file) {

    echo "<tr>
                <td>{$file['name']}</td>
                <td>{$file['size']}</td>
                <td>{$file['rights']}</td>
                <td>{$file['type']}</td>
                <td>{$file['date']}</td>
            </tr>";
}

echo "</table>";
?>

примерно так должно отработать :
 

Вложения

  • screen.png
    screen.png
    48,6 KB · Просмотры: 14
Назад
Сверху