Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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) 
TransmissionModelFile Object
(
    [name:protected] => RootFolder/Folder1/File1.jpg
    [size:protected] => 13324
    [completed:protected] => 13324
    [client:protected] => 
)

$files will output:

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

[1] => TransmissionModelFile 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
129 views
Welcome To Ask or Share your Answers For Others

1 Answer

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?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...