Page 1 of 1

File size in a array.

Posted: Fri May 04, 2007 3:58 am
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

Posted: Fri May 04, 2007 4:31 am
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);

Posted: Fri May 04, 2007 4:46 am
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

Posted: Fri May 04, 2007 5:47 am
by onion2k
Look at your code again. The problem is obvious.

Posted: Fri May 04, 2007 8:31 am
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