suttercain Posted April 22, 2007 Share Posted April 22, 2007 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! Link to comment https://forums.phpfreaks.com/topic/48166-error-cannot-redeclare-downloadsize-previously-declared-in/ Share on other sites More sharing options...
Navarr Posted April 22, 2007 Share Posted April 22, 2007 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). Link to comment https://forums.phpfreaks.com/topic/48166-error-cannot-redeclare-downloadsize-previously-declared-in/#findComment-235466 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.