Jump to content

Recommended Posts

I want to get the file size for each zip file in a folder

I works it there is only one, but more than one I get an error

Fatal error: Cannot redeclare bytesize() (previously declared in /**/downloads.php:40) in /**/downloads.php on line 40

 

How do I get it to show for each file?

 

Here is the code

<?php
$path = "/**/downloads/";

$zip_files =glob($path."*.zip");

for($index = 0; $index < count($zip_files); $index++) {

$file = basename($zip_files[$index], ".zip");


$bytes = filesize($zip_files[$index]);

function ByteSize($bytes)  //line 40
{
$size = $bytes / 1024;
if($size < 1024)
{
$size = number_format($size, 2);
$size .= ' KB';
}else {
if($size / 1024 < 1024) {
$size = number_format($size / 1024, 2);
$size .= ' MB';
} else if($size / 1024 / 1024 < 1024) {
$size = number_format($size / 1024 / 1024, 2);
$size .= ' GB';
}
}
return $size;
}
?>

 

Thanks in advance

I'm sorry, I don't understand what you mean by including the downloads.php once

Here is the entire page

<?php
session_start();
require("header.php");
$page = curPageName();
$pageName = "Downloads";

?>
<span class="main">Your are here: <a href="<?=$base;?>"><?=$baseName;?></a> >> <a href="<?=$page;?>"><?=$pageName;?></a></span>
          <tr>
            <td height="25"> </td>
          </tr>
          <tr>
            <td height="306" align="center" valign="top" background="img/middle_bg.png"><table width="100%" border="0" cellspacing="0" cellpadding="6">
              <tr>
                <td height="35"><table width="100%" border="0" cellspacing="0" cellpadding="6">
                  <tr>
                    <td><span class="middle"><?=$pageName;?></span></td>
                  </tr>
                </table></td>
                </tr>
              <tr>
                <td align="center" valign="middle">
                <table width="100%" border="0" cellspacing="0" cellpadding="6">
                  <tr>
                    <td><strong>Applicantions</strong></td>
                    <td><strong>Download</strong></td>
                  </tr>
<?php
$path = "/**/downloads/";

$zip_files =glob($path."*.zip");

for($index = 0; $index < count($zip_files); $index++) {

$file = basename($zip_files[$index], ".zip");

$bytes = filesize($zip_files[$index]);

function ByteSize($bytes)
{
$size = $bytes / 1024;
if($size < 1024)
{
$size = number_format($size, 2);
$size .= ' KB';
}else {
if($size / 1024 < 1024) {
$size = number_format($size / 1024, 2);
$size .= ' MB';
} else if($size / 1024 / 1024 < 1024) {
$size = number_format($size / 1024 / 1024, 2);
$size .= ' GB';
}
}
return $size;
}

?>
<tr>
<td><?=$file; ?></td>
<td class="main">
<a href="downloads/download.php?f=<?=$zip_files[$index] ?>">Download Now</a> <?=ByteSize($bytes);?></tr>                   
<?php
}
?>
</table>
                <br /></td>
              </tr>
              <tr>
                <td> </td>
                </tr>
            </table></td>
          </tr>
        </table></td>
        <td align="right" valign="top" bgcolor="#191b10"> </td>
      </tr>
      
      <!--Begin Footer-->
<?php
require("footer.php");
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.