File size in a array.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gcclinux
Forum Newbie
Posts: 6
Joined: Thu May 03, 2007 6:11 am

File size in a array.

Post by gcclinux »

I am trying to add the file size of the last created tar files that gets listed in a array but for some reason "filesize($finalname)" does not work.

Code: Select all

<td height="0" width="100%" bgcolor="#EFF3F7" bordercolor="#FFFFFF">
        <font face="Verdana"><?php
        $dir_list = dir_to_array('/Backups/System2/'.$LAST,'.*.gz');
                foreach ($dir_list as $filename)
                echo "<br><li>LAST BACKUP FILES = $filename filesize($filename)";
        ?>
        </td>
This is the output I get:
# LAST BACKUP FILES = etc-1.tar.gz filesize(etc-1.tar.gz)
# LAST BACKUP FILES = healthcheck-1.tar.gz filesize(healthcheck-1.tar.gz)
# LAST BACKUP FILES = srv-1.tar.gz filesize(srv-1.tar.gz)
Any suggestion will be greatly appreciated.

Many Thanks in advance.

Ricardo
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

You can't call a function in the middle of a string. Change it to..

Code: Select all

echo "<br><li>LAST BACKUP FILES = $filename ".filesize($filename);
gcclinux
Forum Newbie
Posts: 6
Joined: Thu May 03, 2007 6:11 am

Post by gcclinux »

Thanks for the info, that almost works apart from the fact that it can't find the file :-P

Output:
Warning: filesize(): Stat failed for etc-1.tar.gz (errno=2 - No such file or directory) in /opt/healthcheck/apache2/index.php on line 331

# LAST BACKUP FILES = etc-1.tar.gz
Warning: filesize(): Stat failed for healthcheck-1.tar.gz (errno=2 - No such file or directory) in /opt/healthcheck/apache2/index.php on line 331

# LAST BACKUP FILES = healthcheck-1.tar.gz
Warning: filesize(): Stat failed for srv-1.tar.gz (errno=2 - No such file or directory) in /opt/healthcheck/apache2/index.php on line 331

# LAST BACKUP FILES = srv-1.tar.gz
It does not seem to be taking the full PATH of the file that is specified in the "dir_to_array" and when I tried to add the PATH as specified in the "dir_to_array" it does not work! :-(

Any more suggestions in how I can add

Code: Select all

echo "<br><li>LAST BACKUP FILES = $filename " .filesize('/Backups/System2/'.$LAST,'.$filename);
as the above syntax also does not work. :-(

Many thanks in advance.

Ricardo
User avatar
onion2k
Jedi Mod
Posts: 5263
Joined: Tue Dec 21, 2004 5:03 pm
Location: usrlab.com

Post by onion2k »

Look at your code again. The problem is obvious.
gcclinux
Forum Newbie
Posts: 6
Joined: Thu May 03, 2007 6:11 am

Post by gcclinux »

onion2k wrote:Look at your code again. The problem is obvious.
Workable syntax.

Code: Select all

<tr>
        <td height="0" width="100%" bgcolor="#EFF3F7" bordercolor="#FFFFFF">
        <font face="Verdana"><?php
        $dir_list = dir_to_array('/Backups/System2/'.$LAST,'.*.gz');
                foreach ($dir_list as $filename)
                echo "<br><li>LAST BACKUP FILES = $filename - Size " .filesize('/Backups/System2/'.$LAST.'/'.$filename) . ' Bytes ';
        ?>
        </td>
Ricardo
Post Reply