Index: trunk/core/kernel/globals.php =================================================================== diff -u -N -r3523 -r3543 --- trunk/core/kernel/globals.php (.../globals.php) (revision 3523) +++ trunk/core/kernel/globals.php (.../globals.php) (revision 3543) @@ -394,5 +394,54 @@ { return round(($pounds + ($ounces / 16)) * POUND_TO_KG, 5); } + + /** + * Formats file/memory size in nice way + * + * @param int $bytes + * @return string + * @access public + */ + function formatSize($bytes) + { + if ($bytes >= 1099511627776) { + $return = round($bytes / 1024 / 1024 / 1024 / 1024, 2); + $suffix = "TB"; + } elseif ($bytes >= 1073741824) { + $return = round($bytes / 1024 / 1024 / 1024, 2); + $suffix = "GB"; + } elseif ($bytes >= 1048576) { + $return = round($bytes / 1024 / 1024, 2); + $suffix = "MB"; + } elseif ($bytes >= 1024) { + $return = round($bytes / 1024, 2); + $suffix = "KB"; + } else { + $return = $bytes; + $suffix = "Byte"; + } + $return .= ' '.$suffix; + return $return; + } + + /** + * Enter description here... + * + * @param resource $filePointer the file resource to write to + * @param Array $data the data to write out + * @param string $delimiter the field separator + * @param string $enclosure symbol to enclose field data to + * @param string $recordSeparator symbols to separate records with + */ + function fputcsv2($filePointer, $data, $delimiter = ',', $enclosure = '"', $recordSeparator = "\r\n") + { + foreach($data as $field_index => $field_value) { + // replaces an enclosure with two enclosures + $data[$field_index] = str_replace($enclosure, $enclosure.$enclosure, $field_value); + } + $line = $enclosure.implode($enclosure.$delimiter.$enclosure, $data).$enclosure.$recordSeparator; + fwrite($filePointer, $line); + } + ?> \ No newline at end of file