--- /dev/null
+<?php
+/**
+ * dolphin. Collection of useful PHP skeletons.
+ * Copyright (C) 2019 Johannes 'Banana' Keßler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program. If not, see http://www.sun.com/cddl/cddl.html
+ */
+
+/**
+ * Get the folder size with a unix command.
+ * Usefull when on linux only and large files
+ *
+ * @param string $folder Absolute path to the folder
+ */
+function folderSize($folder) {
+ $io = popen ( '/usr/bin/du -sk ' . folder, 'r' );
+ $size = fgets ( $io, 4096);
+ $size = substr ( $size, 0, strpos ( $size, "\t" ) );
+ pclose ( $io );
+
+ return $size;
+}
--- /dev/null
+<?php
+/**
+ * dolphin. Collection of useful PHP skeletons.
+ * Copyright (C) 2019 Johannes 'Banana' Keßler
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE
+ *
+ * You should have received a copy of the
+ * COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0
+ * along with this program. If not, see http://www.sun.com/cddl/cddl.html
+ */
+
+/**
+ * Simple functon to get the size of a folder
+ * ignores . files and does not really work well with large files
+ *
+ * @param string $folder Absolute path to folder
+ */
+function folderSize($folder) {
+ $ret = 0;
+
+ if(file_exists($folder) && is_readable($folder)) {
+ foreach (glob(rtrim($folder, '/') . '/*', GLOB_NOSORT) as $each) {
+ $ret += is_file($each) ? filesize($each) : folderSize($each);
+ }
+ }
+
+ return $ret;
+}