Jump to content

ERROR: Cannot redeclare downloadsize() (previously declared in...


suttercain

Recommended Posts

Hi everyone,

 

I am trying to get the filesize converted to MB, GB, etc and am using a user function for this. My problem is that when it is first echoed the first result from the while loop is displayed correctly, but when it hits what should be the second row from the while loop I get this error:

 

Fatal error: Cannot redeclare downloadsize() (previously declared in /home/superman/public_html/multimedia/view_video.php:31) in /home/superman/public_html/multimedia/view_video.php on line 31

 

Here is the code I am using:

<?php
$result1 = mysql_query("SELECT * FROM multimedia WHERE title='" . $row['title'] . "' AND type='video'");
while($row1 = mysql_fetch_array($result1)){
$file = "/home/superman/public_html/multimedia/video/" . $row1['link'] ."";
		function DownloadSize($file) {
  			$size = filesize($file);
  			$sizes = Array('B', 'KB', 'MB', 'GB', 'TB', 'PB', 'EB');
  			$ext = $sizes[0];
  			for ($i=1; (($i < count($sizes)) && ($size >= 1024)); $i++) {
   			$size = $size / 1024;
   			$ext  = $sizes[$i];
  											}
  			return round($size, 2).$ext;
										}
	echo DownloadSize($file);
                        }
?>

 

Is it possible to display the filesize for multiple files from within the while loop? How do I rectify this?

 

Thanks!

 

Okay, Your code is really messed up, and I'm not entirely sure how to fix it as is.  But I can tell you your problem.  Your function is being declared inside of a while loop.  That means, that each time the while loop runs, it redeclares the function.  Thats a bad thing.  A function can only be declared once.  You need to move your function outside of the while loop, and use it as an external function (just like you would normal php commands).

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.