如何从一个对象创建一个像表一样的文件树? [英] How to create a filetree like table from an object?

查看:112
本文介绍了如何从一个对象创建一个像表一样的文件树?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我第一次发布 时,我有点困惑>。这一次,我会更具体。



我试图从一个对象(来自php传输项目)。在我的表中,我会有文件名,大小和状态(完成与否)。在名称中,我们可以看到某种文件完整路径字符串。



托马斯帮助我制作了一系列名字,但我忘记告诉他我试图从一个对象中抓取它。



以下是我的代码示例:

 <?php 
$ transmission = new Transmission();
$ transfer = $ transmission-> get('26ec249e2669388ff359923702ac0f5c7687d1be');
$ files = $ transfer-> getFiles();


foreach($ files AS $ file)
{
var_dump($ file-> getName()); // RootFolder / Folder1 / File1.jpg
var_dump($ file-> getSize()); // 10383488
var_dump($ file-> isDone()); // True or False

print_r($ file);
}

输出:

  string(59)RootFolder / Folder1 / File1.jpg
int(13324)
bool(true)
Transmission \Model\File Object

[name:protected] => RootFolder / Folder1 / File1.jpg
[size:protected] => 13324
[完成:保护] => 13324
[客户端:保护] =>


$ b $

$ $ b $ $ b $ $ b $ $ b $ $ $ $ $ $ $ $ [0] => Transmission \Model\File Object

[name:protected] => RootFolder / Folder1 / File1.jpg
[size:protected] => 13324
[completed:protected] => 13324
[client:protected] =>


[1] => Transmission\Model\\ \\ File Object

[name:protected] => RootFolder / Folder1 / File2.mp3
[size:protected] => 10383488
[已完成: protected] => 10383488
[client:protected] =>

[2] ...

I从 www.abeautifulsite.net 看到了不错的作品,但它基于 is_dir()命令。



我想要做的是在文件行上包含可折叠部分(位于文件夹中)和文件信息(名称,大小和状态)的html表格。 b
$ b

有什么想法?

解决方案

我找到了我的问题的第一部分的答案。这是我的代码(基于我的旧帖子):

$ p $ function createArray($ filesObject)
{
$ result = array();
foreach($ filesObject AS $ file)
{
$ prev =& $ result;
$ s = strtok($ file-> getName(),'/'); ($($ next)= strtok('/'))!== false)

if(!isset($ prev [$ s])){
$ prev [$ s] = array();
}

$ prev =& $ prev [$ s];
$ s = $ next;

$ b $ prev [] = $ s。'|'。$ file-> getSize()。'|'。$ file-> isDone(); //分隔符是'|'
unset($ prev);
}
返回$ result;





$ b

第二部分是以某种文件树样式html表。
如果有人有想法?


I was a little bit confused when I made my first post. This time I'll be more specific.

I'm trying to make a "filetree-like" table from an object (From a php-transmission project). In my table I would have the filename, the size and the status (done or not). In the "Name" we can see some kind of "full path to file" string.

Thomas helped me out of making an array of names, but I forgot telling him that I was trying to grab it from an object..

Here is a sample of my code:

<?php
$transmission = new Transmission();
$transfer= $transmission->get('26ec249e2669388ff359923702ac0f5c7687d1be');  
$files = $transfer->getFiles();


foreach($files AS $file) 
    {
    var_dump($file->getName()); // RootFolder/Folder1/File1.jpg
    var_dump($file->getSize()); // 10383488
    var_dump($file->isDone());  // True or False

    print_r($file);
    }

Output:

string(59) "RootFolder/Folder1/File1.jpg" 
int(13324) 
bool(true) 
Transmission\Model\File Object
(
    [name:protected] => RootFolder/Folder1/File1.jpg
    [size:protected] => 13324
    [completed:protected] => 13324
    [client:protected] => 
)

$files will output:

Array
(
[0] => Transmission\Model\File Object
    (
        [name:protected] => RootFolder/Folder1/File1.jpg
        [size:protected] => 13324
        [completed:protected] => 13324
        [client:protected] => 
    )

[1] => Transmission\Model\File Object
    (
        [name:protected] => RootFolder/Folder1/File2.mp3
        [size:protected] => 10383488
        [completed:protected] => 10383488
        [client:protected] => 
    )
[2] ...
)

I saw a nice work from www.abeautifulsite.net, but it's based on is_dir() command.

What I want to do is a html table with collapsible parts (on folders) and files info (name, size and status) on file rows.

Any ideas?

解决方案

I found the answer of the first part of my problem. Here's my code (based on my old post):

function createArray ($filesObject)
  {
  $result = array();
  foreach($filesObject AS $file) 
    {
    $prev = &$result;
    $s = strtok($file->getName(), '/');

     while (($next = strtok('/')) !== false) 
        {
        if (!isset($prev[$s])) {
        $prev[$s] = array();
        }

        $prev = &$prev[$s];
        $s = $next;
        }

    $prev[] = $s.'|'.$file->getSize().'|'.$file->isDone(); // Delimiter is '|'
    unset($prev);
    }
  return $result;
  }

The second part consists in displaying this array in some kind of file tree style html table. If someone have anny ideas?

这篇关于如何从一个对象创建一个像表一样的文件树?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆