
function size_readable ($size, $retstring = null) {
// adapted from code at http://aidanlister.com/repos/v/function.size_readable.php
$sizes = array('B', 'kB', 'MB', 'GB', 'TB', 'PB', 'EB', 'ZB', 'YB');
if ($retstring === null) { $retstring = '%01.2f %s'; }
$lastsizestring = end($sizes);
foreach ($sizes as $sizestring) {
if ($size < 1024) { break; }
if ($sizestring != $lastsizestring) { $size /= 1024; }
}
if ($sizestring == $sizes[0]) { $retstring = '%01d %s'; } // Bytes aren't normally fractional
return sprintf($retstring, $size, $sizestring);
}
$pics[$i]['title'] = stripslashes($pics[$i]['title']);
$pics[$i]['descr'] = stripslashes($pics[$i]['descr']);
$pictureTplData['picture'] = $pics[$i];
$pictureTplData['counter'] = $pic_number;
$pictureTplData['picture_height_big'] = $imagesize[1];
$pictureTplData['picture_width_big'] = $imagesize[0];
$pictureTplData['picture_bigsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal."big_".$pics[$i]['filename']));
$pictureTplData['picture_normalsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal . $pics[$i]['filename']));
$pictureTplData['picture_thumbsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal."tn_".$pics[$i]['filename']));
if(file_exists($modx->config['base_path'].$mg->path_to_gal."big_".$pics[$i]['filename'])){
$imagesize=getimagesize($modx->config['base_path'].$mg->path_to_gal."big_".$pics[$i]['filename']);
$pictureTplData['picture_height_big'] = $imagesize[1];
$pictureTplData['picture_width_big'] = $imagesize[0];
$pictureTplData['big_pic_exists'] = 1;
$pictureTplData['picture_bigsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal."big_".$pics[$i]['filename']));
} else {
$pictureTplData['big_pic_exists'] = 0;
}
if(file_exists($modx->config['base_path'].$mg->path_to_gal.$pics[$i]['filename'])) {
$imagesize=getimagesize($modx->config['base_path'].$mg->path_to_gal.$pics[$i]['filename']);
$pictureTplData['picture_height_normal'] = $imagesize[1];
$pictureTplData['picture_width_normal'] = $imagesize[0];
$pictureTplData['picture_normalsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal . $pics[$i]['filename']));
}
if(file_exists($modx->config['base_path'].$mg->path_to_gal."tn_".$pics[$i]['filename'])) {
$imagesize=getimagesize($modx->config['base_path'].$mg->path_to_gal."tn_".$pics[$i]['filename']);
$pictureTplData['picture_height_thumb'] = $imagesize[1];
$pictureTplData['picture_width_thumb'] = $imagesize[0];
$pictureTplData['picture_thumbsize'] = size_readable(filesize($modx->config['base_path'].$mg->path_to_gal."tn_".$pics[$i]['filename']));
}
if (function_exists("formatbytes") === FALSE) {
# Format byte size according to selected mode
# Courtesy of [email protected]
function formatbytes($val, $digits = 3, $mode = "SI", $bB = "B"){ //$mode == "SI"|"IEC", $bB == "b"|"B"
$si = array("", "k", "M", "G", "T", "P", "E", "Z", "Y");
$iec = array("", "Ki", "Mi", "Gi", "Ti", "Pi", "Ei", "Zi", "Yi");
switch(strtoupper($mode)) {
case "SI" : $factor = 1000; $symbols = $si; break;
case "IEC" : $factor = 1024; $symbols = $iec; break;
default : $factor = 1000; $symbols = $si; break;
}
switch($bB) {
case "b" : $val *= 8; break;
default : $bB = "B"; break;
}
for($i=0;$i<count($symbols)-1 && $val>=$factor;$i++)
$val /= $factor;
$p = strpos($val, ".");
if($p !== false && $p > $digits) $val = round($val);
elseif($p !== false) $val = round($val, $digits-$p);
return round($val, $digits) . " " . $symbols[$i] . $bB;
}
}
$pictureTplData[’picture_bigsize’] = formatbytes(filesize($mg->path_to_gal."big_".$pics[$i][’filename’]), 3, "SI", "B");
$pictureTplData[’picture_bigsize’] = size_readable(filesize($modx->config[’base_path’].$mg->path_to_gal."big_".$pics[$i][’filename’]));
<?php
echo filesize('/full/path/to/image.jpg'); // test with full path
echo '<br />';
echo filesize('/path/to/image.jpg'); // test with relative path
?>
# get file size
$file[’filesize’] = formatbytes(filesize($filepath), $digits, $byteMode, "B");
<?php
echo filesize(’http://ns*****.ovh.net/~secusol/assets/galleries/833/big_1big_946013_53113128.jpg’); // test with full path
echo ’
’;
echo filesize(’assets/galleries/833/big_1big_946013_53113128.jpg’); // test with relative path
?>
Warning: filesize() [function.filesize]: stat failed for http://ns29452.ovh.net/~secusol/assets/galleries/833/big_1big_946013_53113128.jpg in /home/secusol/domains/soleil.info/public_html/test_filesize.php on line 2 1243422
/home/domain/public_html/assets/...