timmah1 Posted January 11, 2009 Share Posted January 11, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/140408-solved-file-size-error-with-more-than-one-file/ Share on other sites More sharing options...
Mark Baker Posted January 11, 2009 Share Posted January 11, 2009 Define the function bytesize before the loop Quote Link to comment https://forums.phpfreaks.com/topic/140408-solved-file-size-error-with-more-than-one-file/#findComment-734846 Share on other sites More sharing options...
timmah1 Posted January 11, 2009 Author Share Posted January 11, 2009 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"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/140408-solved-file-size-error-with-more-than-one-file/#findComment-734850 Share on other sites More sharing options...
timmah1 Posted January 11, 2009 Author Share Posted January 11, 2009 Got it Thanks Mark Quote Link to comment https://forums.phpfreaks.com/topic/140408-solved-file-size-error-with-more-than-one-file/#findComment-734851 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.