skot Posted March 2, 2008 Share Posted March 2, 2008 Hey I've been trying to no avail to integrate a bytes to megabytes script in with a directory listing script i'm using, which runs through an array of files and shows their filesize in bytes. Trouble is im getting the following error: Fatal error: Can't use function return value in write context in /home/bridgey/public_html/music/index.php on line 115 Here is the code being used. Can anyone tell me what this is doing wrong? <?php 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; } // Returns '19.28mb' ByteSize('$sizeinb'); ?> <?php // open this directory $myDirectory = opendir("."); // get each entry while($entryName = readdir($myDirectory)) { $dirArray[] = $entryName; } // close directory closedir($myDirectory); // count elements in array $indexCount = count($dirArray); Print ("<font face=verdana size=3 color=#F8F304><B>:: To download right click on a song and 'save as...'</B><br><br>:: To upload click the link at the top.</font><br>\n"); // sort 'em sort($dirArray); // print 'em print("<TABLE border=0 cellpadding=1 cellspacing=0 class=whitelinks>\n"); print("<TR><TH><font face=verdana size=2><B>Name</TH><th>Type</th><th>Size</th></B></font></TR>\n"); // loop through the array of files and print them all for($index=0; $index < $indexCount; $index++) { if (substr("$dirArray[$index]", 0, 1) != "."){ // don't list hidden files print("<TR><TD><img src=http://bridgey.net/img/main_icon.gif border=0></img> <font face=verdana size=2><b><a href=\"$dirArray[$index]\">$dirArray[$index]</a></b></font></td>"); print("<td>"); print(filetype($dirArray[$index])); print("</td>"); print("<td>"); filesize($dirArray[$index]) = $sizeinb; print($sizeinmb); print("</td>"); print("</TR>\n"); } } print("</TABLE>\n"); ?> Any help would be great ~ Thanks. Link to comment https://forums.phpfreaks.com/topic/94092-converting-a-filesize-from-bytes-to-megabytes-using-php-little-help/ Share on other sites More sharing options...
KrisNz Posted March 3, 2008 Share Posted March 3, 2008 filesize($dirArray[$index]) = $sizeinb; $sizeinb = filesize($dirArray[$index]) ; Link to comment https://forums.phpfreaks.com/topic/94092-converting-a-filesize-from-bytes-to-megabytes-using-php-little-help/#findComment-482012 Share on other sites More sharing options...
skot Posted March 3, 2008 Author Share Posted March 3, 2008 Have changed that line as advised and the script doesnt show the filesize at all now Link to comment https://forums.phpfreaks.com/topic/94092-converting-a-filesize-from-bytes-to-megabytes-using-php-little-help/#findComment-482029 Share on other sites More sharing options...
skot Posted March 10, 2008 Author Share Posted March 10, 2008 Hi. Im posting this message as I havent received a response in over a week, in the hope that someone will see this and reply Link to comment https://forums.phpfreaks.com/topic/94092-converting-a-filesize-from-bytes-to-megabytes-using-php-little-help/#findComment-488938 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.