How to create a table file similar to a table from an object?

I was a little embarrassed when I made my first post . This time I will be more specific.

I am trying to create a "filetree-like" table from an object ( from a php transfer project ). My table would have a file name, size and status (done or not). In "Name" we can see some line "full path to the file".

Thomas helped me create an array of names, but I forgot to tell him that I was trying to grab it from the object.

Here is an example 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] => ) 

$ will be 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 good job from www.abeautifulsite.net , but based on the is_dir() command.

What I want to do is an html table with folding parts (by folders) and file information (name, size and status) in the lines of the file.

Any ideas?

-1
source share
1 answer

I found the answer to the first part of my problem. Here is 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 as an html table such as a file tree. If anyone has any ideas?

0
source

Source: https://habr.com/ru/post/956667/


All Articles