• Welcome to the Chevereto user community!

    Here users from all over the world gather around to learn the latest about Chevereto and contribute with ideas to improve the software.

    Please keep in mind:

    • 😌 This community is user driven. Be polite with other users.
    • 👉 Is required to purchase a Chevereto license to participate in this community (doesn't apply to Pre-sales).
    • 💸 Purchase a Pro Subscription to get access to active software support and faster ticket response times.

Imagecounter in Footer

This shows the image counter and the total size (function reused from above) :

X images uploaded for a total of X

Code:
<?php 
    function showSize($size_in_bytes) {
        $value = 0;        
        if ($size_in_bytes >= 1073741824) {
            $value = round($size_in_bytes/1073741824*10)/10;
            return  ($round) ? round($value) . 'Gb' : "{$value} GB";
        } else if ($size_in_bytes >= 1048576) {
            $value = round($size_in_bytes/1048576*10)/10;
            return  ($round) ? round($value) . 'Mb' : "{$value} MB";
        } else if ($size_in_bytes >= 1024) {
            $value = round($size_in_bytes/1024*10)/10;
            return  ($round) ? round($value) . 'Kb' : "{$value} KB";
        } else {
            return "$size_in_bytes bytes";
        }
    }
    $db = mysql_connect('localhost', 'DATABASE_LOGIN', 'DATABASE_PASSWORD'); 
    mysql_select_db('DATABASE_NAME',$db);  
    $sql = 'SELECT count(image_id), sum(image_size) FROM chv_images'; 
    $req = mysql_query($sql) or die('SQL Error !<br>'.$sql.'<br>'.mysql_error()); 
    $data = mysql_fetch_assoc($req);
    echo $data['count(image_id)'].' images uploaded for a total of '.showSize($data['sum(image_size)']); 
    mysql_close(); 
?>

I'd like to get more documentation about the built in pdo query stuff to make a better imagecounter ;)
 
rain, how to make it look like this please:
Total of XXX images uploaded using YYY of space
?

Thanks in advance :)
 
Code:
<?php 
    function showSize($size_in_bytes) {
        $value = 0;        
        if ($size_in_bytes >= 1073741824) {
            $value = round($size_in_bytes/1073741824*10)/10;
            return  ($round) ? round($value) . 'Gb' : "{$value} GB";
        } else if ($size_in_bytes >= 1048576) {
            $value = round($size_in_bytes/1048576*10)/10;
            return  ($round) ? round($value) . 'Mb' : "{$value} MB";
        } else if ($size_in_bytes >= 1024) {
            $value = round($size_in_bytes/1024*10)/10;
            return  ($round) ? round($value) . 'Kb' : "{$value} KB";
        } else {
            return "$size_in_bytes bytes";
        }
    }
    $db = mysql_connect('localhost', 'DATABASE_LOGIN', 'DATABASE_PASSWORD'); 
    mysql_select_db('DATABASE_NAME',$db);  
    $sql = 'SELECT count(image_id), sum(image_size) FROM chv_images'; 
    $req = mysql_query($sql) or die('SQL Error !<br>'.$sql.'<br>'.mysql_error()); 
    $data = mysql_fetch_assoc($req);
    echo 'Total of '.$data['count(image_id)'].' images uploaded using '.showSize($data['sum(image_size)']).' of space'; 
    mysql_close(); 
?>

This.
 
Thank you very much! :)
One more question though (of course, if it is possible)...
is there a way to make the numbers (images and size) red so they'll get noticed better?

Thank you again.
 
Code:
<?php 
    function showSize($size_in_bytes) {
        $value = 0;        
        if ($size_in_bytes >= 1073741824) {
            $value = round($size_in_bytes/1073741824*10)/10;
            return  ($round) ? round($value) . 'Gb' : "{$value} GB";
        } else if ($size_in_bytes >= 1048576) {
            $value = round($size_in_bytes/1048576*10)/10;
            return  ($round) ? round($value) . 'Mb' : "{$value} MB";
        } else if ($size_in_bytes >= 1024) {
            $value = round($size_in_bytes/1024*10)/10;
            return  ($round) ? round($value) . 'Kb' : "{$value} KB";
        } else {
            return "$size_in_bytes bytes";
        }
    }
    $db = mysql_connect('localhost', 'DATABASE_LOGIN', 'DATABASE_PASSWORD'); 
    mysql_select_db('DATABASE_NAME',$db);  
    $sql = 'SELECT count(image_id), sum(image_size) FROM chv_images'; 
    $req = mysql_query($sql) or die('SQL Error !<br>'.$sql.'<br>'.mysql_error()); 
    $data = mysql_fetch_assoc($req);
    echo 'Total of <font color="red">'.$data['count(image_id)'].'</font> images uploaded using <font color="red">'.showSize($data['sum(image_size)']).'</font> of space'; 
    mysql_close(); 
?>

This.
 
why are you guys doing a new connection while you already have the built in pdo query method ?
 
I'd like to get more documentation about the built in pdo query stuff to make a better imagecounter ;)

I'd love to use the pdo query BUT i didn't find any documentation about it so I dunno how to use it, as I said earlier !
 
I'd love to use the pdo query BUT i didn't find any documentation about it so I dunno how to use it, as I said earlier !

take a look at class.db.php and class.upload.php, you can pretty much understand how it works by looking at the code there
 
You don't need documentation.. Just run a PDO query using the $db object that comes un class.db.php
 
I used the integrated total_images_uploaded(); function found in functions.php

PHP:
<br /><p><?php echo "Hosted Images: ".number_format(total_images_uploaded()).""; ?></p>

In my footer.php

PHP:
<div id="foot">
    <div id="in-foot">
        <div id="foot-content">
            <ul>
                <?php show_page_links('<li>'); ?>
                <?php if(is_logged_user() || is_admin()) :?><li><a rel="logout"><?php show_lang_txt('txt_logout'); ?></a></li><?php endif; ?>
            </ul>
            <br /><p><?php echo "Hosted Images: ".number_format(total_images_uploaded()).""; ?></p>
            <p>(C) 2012 <a href="http://chevereto.com/" target="_blank" title="Chevereto Image Upload Script" id="c_chevereto">Chevereto</a></p>
        </div>

Works pretty much anywhere, Figure I'll share this solution instead of creating a new function.
 
If you want to show the space used, add these two functions below to your functions.php :

PHP:
/**
* total_images_uploaded_size
* returns the total size of images uploaded
*/
 
function total_images_uploaded_size() {
    global $dB;
    $uploaded_qry = $dB->query_fetch_single("SELECT sum(image_size) as total FROM chv_images;");
    return $uploaded_qry["total"];
}
 
/**
* showSize
* returns the value in Gb, Mb or Kb
*/
 
function showSize($size_in_bytes) {
    $value = 0; 
    if ($size_in_bytes >= 1073741824) {
        $value = round($size_in_bytes/1073741824*10)/10;
        return  ($round) ? round($value) . 'Gb' : "{$value} GB";
    } else if ($size_in_bytes >= 1048576) {
        $value = round($size_in_bytes/1048576*10)/10;
        return  ($round) ? round($value) . 'Mb' : "{$value} MB";
    } else if ($size_in_bytes >= 1024) {
        $value = round($size_in_bytes/1024*10)/10;
        return  ($round) ? round($value) . 'Kb' : "{$value} KB";
    } else {
        return "$size_in_bytes bytes";
    }
}

Then in your footer.php or wherever, add this :

PHP:
<?php echo showSize(total_images_uploaded_size()); ?>

You can now show something like this using all functions :
xkQa.png
 
This doesn't work for me, i used to. Once i installed AUS, however. It did no longer.

PHP:
<br /><?php echo "Hosted Images: ".number_format(total_images_uploaded()).""; ?>
<br />
<?
//To calculate and count directories//GNU GPL v3 - LMPF
 
function getDirectorySize($path)
{
  $totalsize = 0;
  $totalcount = 0;
  $dircount = 0;
  if ($handle = opendir ($path))
  {
    while (false !== ($file = readdir($handle)))
    {
      $nextpath = $path . '/' . $file;
      if ($file != '.' && $file != '..' && !is_link ($nextpath))
      {
        if (is_dir ($nextpath))
        {
          $dircount++;
          $result = getDirectorySize($nextpath);
          $totalsize += $result['size'];
          $totalcount += $result['count'];
          $dircount += $result['dircount'];
        }
        elseif (is_file ($nextpath))
        {
          $totalsize += filesize ($nextpath);
          $totalcount++;
        }
      }
    }
  }
  closedir ($handle);
  $total['size'] = $totalsize;
  $total['count'] = $totalcount;
  $total['dircount'] = $dircount;
  return $total;
}
 
function sizeFormat($size)
{
    $sizeStr='';
    if($size<1024)
    {
        return $size." bytes";
    }
    else if($size<(1024*1024))
    {
        $size=round($size/1024,1);
        return $size." KB";
    }
    else if($size<(1024*1024*1024))
    {
        $size=round($size/(1024*1024),1);
        return $size." MB";
    }
    else
    {
        $size=round($size/(1024*1024*1024),1);
        return $size." GB";
    }
 
}
 
$path="images/";
$ar=getDirectorySize($path);
 
echo "Space Used : ".sizeFormat($ar['size'])."<br>";
 
//print_r($ar);
?>

Even that? Because it's working for me.
 
PHP:
<br /><?php echo "Hosted Images: ".number_format(total_images_uploaded()).""; ?>
<br />
<?
//To calculate and count directories//GNU GPL v3 - LMPF
 
function getDirectorySize($path)
{
  $totalsize = 0;
  $totalcount = 0;
  $dircount = 0;
  if ($handle = opendir ($path))
  {
    while (false !== ($file = readdir($handle)))
    {
      $nextpath = $path . '/' . $file;
      if ($file != '.' && $file != '..' && !is_link ($nextpath))
      {
        if (is_dir ($nextpath))
        {
          $dircount++;
          $result = getDirectorySize($nextpath);
          $totalsize += $result['size'];
          $totalcount += $result['count'];
          $dircount += $result['dircount'];
        }
        elseif (is_file ($nextpath))
        {
          $totalsize += filesize ($nextpath);
          $totalcount++;
        }
      }
    }
  }
  closedir ($handle);
  $total['size'] = $totalsize;
  $total['count'] = $totalcount;
  $total['dircount'] = $dircount;
  return $total;
}
 
function sizeFormat($size)
{
    $sizeStr='';
    if($size<1024)
    {
        return $size." bytes";
    }
    else if($size<(1024*1024))
    {
        $size=round($size/1024,1);
        return $size." KB";
    }
    else if($size<(1024*1024*1024))
    {
        $size=round($size/(1024*1024),1);
        return $size." MB";
    }
    else
    {
        $size=round($size/(1024*1024*1024),1);
        return $size." GB";
    }
 
}
 
$path="images/";
$ar=getDirectorySize($path);
 
echo "Space Used : ".sizeFormat($ar['size'])."<br>";
 
//print_r($ar);
?>

Even that? Because it's working for me.

Yeah i fixed it, i put it in the functions.php file in my theme folder, it works fine in includes/functions.php, silly me haha
 
I have 18 images uploaded on my site, but it states that 0 Images have been uploaded so far. Help :'( I used the code from the first code
 
Back
Top