Jump to content

Converting a filesize from bytes to megabytes using PHP - Little help?


skot

Recommended Posts

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
Share on other sites

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.