Disk Quota Suggestion

Have a question or a suggestion about a 3rd party addon module or plugin?
Let us know here.
Locked
gazoo

Disk Quota Suggestion

Post by gazoo »

Hello,

I have a suggestion for this great CMS and also a code snippet but require some assistance to hopefully integrate this into CMSMS.

The idea is to be able to implement a disk quota on the total files in the uploads directory. In other words, assuming that a disk quota of 10 MB is implemented, then the user should not be able to upload a file via the File Manager or Image Manager if the total files in the directory will be 10 MB or more (including the file to be uploaded).

I have enclosed a generic code snippet that works on its own as a function call. It returns the number of bytes in a directory.

Code: Select all

<?php
/*
*  Returns disk usage in bytes of directory $d. Limit depth level with $depth.
*/

function disk_usage($d, $depth = NULL) {

  if(is_file($d)) {
    return filesize($d);
  }

  if(isset($depth) && $depth < 0) {
    return 0;
  }
  
  if($d[strlen($d)-1] != "\\" || $d[strlen($d)-1] != "/") {
    $d .= "/";
  }
    
  $dh=@opendir($d);

  if(!$dh) {
    return 0;
  }

  while($e = readdir($dh)) {
    if($e != "." && $e != "..") {
      $usage += disk_usage($d.$e, isset($depth) ? $depth - 1 : NULL);
    }
  }

  closedir($dh);
  return $usage;
}
?>
I am guessing that it would be a simple matter of adding an if-then clause to determine if the return value is greater than or equal to 10 MB.

However, as I am not really a PHP expert nor do I fully understand the CMSMS code, I wasn't quite sure how I could implement this into CMSMS. I'm not sure if I should be hacking the files.php or imagefiles.php scripts or instead try to implement this as a module.

I think that this would be a useful addition to CMSMS for those that have multiple installations of CMSMS for clients on the same web server but do not have quota management capability at the server level.

I look forward to any help that can be offered.

Cheers!
Gazoo
Locked

Return to “Modules/Add-Ons”