private function updateQuota($dn) { $quota = null; if (!empty($this->ldapQuotaDefault)) { $quota = $this->ldapQuotaDefault; } if (!empty($this->ldapQuotaAttribute)) { $aQuota = OC_LDAP::readAttribute($dn, $this->ldapQuotaAttribute); if ($aQuota && count($aQuota) > 0) { $quota = $aQuota[0]; } } if (!is_null($quota)) { OCP\Config::setUserValue(OC_LDAP::dn2username($dn), 'files', 'quota', OCP\Util::computerFileSize($quota)); } }
/** * Calculate PHP upload limit * * @return int PHP upload file size limit */ public static function uploadLimit() { $ini = \OC::$server->getIniWrapper(); $upload_max_filesize = OCP\Util::computerFileSize($ini->get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize($ini->get('post_max_size')); if ((int) $upload_max_filesize === 0 and (int) $post_max_size === 0) { return INF; } elseif ((int) $upload_max_filesize === 0 or (int) $post_max_size === 0) { return max($upload_max_filesize, $post_max_size); //only the non 0 value counts } else { return min($upload_max_filesize, $post_max_size); } }
* but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU AFFERO GENERAL PUBLIC LICENSE for more details. * * You should have received a copy of the GNU Affero General Public * License along with this library. If not, see <http://www.gnu.org/licenses/>. * */ OCP\User::checkAdminUser(); $htaccessWorking = getenv('htaccessWorking') == 'true'; $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); $maxUploadFilesize = OCP\Util::humanFileSize(min($upload_max_filesize, $post_max_size)); if ($_POST && OC_Util::isCallRegistered()) { if (isset($_POST['maxUploadSize'])) { if (($setMaxSize = OC_Files::setUploadLimit(OCP\Util::computerFileSize($_POST['maxUploadSize']))) !== false) { $maxUploadFilesize = OCP\Util::humanFileSize($setMaxSize); } } } OCP\App::setActiveNavigationEntry("files_administration"); $htaccessWritable = is_writable(OC::$SERVERROOT . '/.htaccess'); $tmpl = new OCP\Template('files', 'admin'); /* * extended version * + only users with permission can delete files(in the files app only) * + file type restriction */ $filetyprestriction = \OC_Appconfig::getValue('core', 'filetyperes_enabled', 'no'); $allowed_types = \OC_Appconfig::getValue('core', 'allowed_filetypes', ''); $deleteGroupsList = \OC_Appconfig::getValue('core', 'delete', '');
$upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); $maxUploadFilesize = OCP\Util::humanFileSize(min($upload_max_filesize, $post_max_size)); if ($_POST && OC_Util::isCallRegistered()) { if (isset($_POST['maxUploadSize'])) { if (($setMaxSize = OC_Files::setUploadLimit(OCP\Util::computerFileSize($_POST['maxUploadSize']))) !== false) { $maxUploadFilesize = OCP\Util::humanFileSize($setMaxSize); } } if (isset($_POST['maxZipInputSize'])) { $maxZipInputSize = $_POST['maxZipInputSize']; OCP\Config::setSystemValue('maxZipInputSize', OCP\Util::computerFileSize($maxZipInputSize)); } if (isset($_POST['submitFilesAdminSettings'])) { OCP\Config::setSystemValue('allowZipDownload', isset($_POST['allowZipDownload'])); } } $maxZipInputSizeDefault = OCP\Util::computerFileSize('800 MB'); $maxZipInputSize = OCP\Util::humanFileSize(OCP\Config::getSystemValue('maxZipInputSize', $maxZipInputSizeDefault)); $allowZipDownload = intval(OCP\Config::getSystemValue('allowZipDownload', true)); OCP\App::setActiveNavigationEntry("files_administration"); $htaccessWritable = is_writable(OC::$SERVERROOT . '/.htaccess'); $tmpl = new OCP\Template('files', 'admin'); $tmpl->assign('uploadChangable', $htaccessWorking and $htaccessWritable); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); // max possible makes only sense on a 32 bit system $tmpl->assign('displayMaxPossibleUploadSize', PHP_INT_SIZE === 4); $tmpl->assign('maxPossibleUploadSize', OCP\Util::humanFileSize(PHP_INT_MAX)); $tmpl->assign('allowZipDownload', $allowZipDownload); $tmpl->assign('maxZipInputSize', $maxZipInputSize); return $tmpl->fetchPage();
$pathtohere = ''; foreach (explode('/', $dir) as $i) { if ($i != '') { $pathtohere .= '/' . str_replace('+', '%20', urlencode($i)); $breadcrumb[] = array('dir' => $pathtohere, 'name' => $i); } } // make breadcrumb und filelist markup $list = new OCP\Template('files', 'part.list', ''); $list->assign('files', $files); $list->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '&dir='); $list->assign('downloadURL', OCP\Util::linkTo('files', 'download.php') . '?file='); $breadcrumbNav = new OCP\Template('files', 'part.breadcrumb', ''); $breadcrumbNav->assign('breadcrumb', $breadcrumb); $breadcrumbNav->assign('baseURL', OCP\Util::linkTo('files', 'index.php') . '&dir='); $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); $maxUploadFilesize = min($upload_max_filesize, $post_max_size); $freeSpace = OC_Filesystem::free_space('/'); $freeSpace = max($freeSpace, 0); $maxUploadFilesize = min($maxUploadFilesize, $freeSpace); $tmpl = new OCP\Template('files', 'index', 'user'); $tmpl->assign('fileList', $list->fetchPage()); $tmpl->assign('breadcrumb', $breadcrumbNav->fetchPage()); $tmpl->assign('dir', $dir); $tmpl->assign('readonly', !OC_Filesystem::is_writable($dir . '/')); $tmpl->assign('files', $files); $tmpl->assign('uploadMaxFilesize', $maxUploadFilesize); $tmpl->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); $tmpl->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); $tmpl->printPage();
/** * @brief calculates the maximum upload size respecting system settings, free space and user quota * * @param $dir the current folder where the user currently operates * @return number of bytes representing */ public static function maxUploadFilesize($dir) { $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); $maxUploadFilesize = min($upload_max_filesize, $post_max_size); $freeSpace = \OC\Files\Filesystem::free_space($dir); if ($freeSpace !== \OC\Files\FREE_SPACE_UNKNOWN) { $freeSpace = max($freeSpace, 0); return min($maxUploadFilesize, $freeSpace); } else { return $maxUploadFilesize; } }
$folder->assign('dirToken', $linkItem['token']); $folder->assign('permissions', OCP\PERMISSION_READ); $folder->assign('isPublic', true); $folder->assign('publicUploadEnabled', 'no'); $folder->assign('files', $files); $folder->assign('uploadMaxFilesize', $maxUploadFilesize); $folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); $folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); $folder->assign('usedSpacePercent', 0); $folder->assign('fileHeader', $fileHeader); $folder->assign('disableSharing', true); $folder->assign('trash', false); $folder->assign('emptyContent', $emptyContent); $folder->assign('ajaxLoad', false); $tmpl->assign('folder', $folder->fetchPage()); $maxInputFileSize = OCP\Config::getSystemValue('maxZipInputSize', OCP\Util::computerFileSize('800 MB')); $allowZip = OCP\Config::getSystemValue('allowZipDownload', true) && ($maxInputFileSize === 0 || $totalSize <= $maxInputFileSize); $tmpl->assign('allowZipDownload', intval($allowZip)); $tmpl->assign('showDownloadButton', intval($allowZip)); $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=' . urlencode($getPath)); } else { $tmpl->assign('showDownloadButton', true); $tmpl->assign('dir', $dir); // Show file preview if viewer is available if ($type == 'file') { $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download'); } else { $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=' . urlencode($getPath)); } } $tmpl->printPage();
$breadcrumbNav->assign('baseURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&path='); $maxUploadFilesize = OCP\Util::maxUploadFilesize($path); $folder = new OCP\Template('files', 'index', ''); $folder->assign('fileList', $list->fetchPage()); $folder->assign('breadcrumb', $breadcrumbNav->fetchPage()); $folder->assign('dir', $getPath); $folder->assign('isCreatable', false); $folder->assign('permissions', OCP\PERMISSION_READ); $folder->assign('isPublic', true); $folder->assign('files', $files); $folder->assign('uploadMaxFilesize', $maxUploadFilesize); $folder->assign('uploadMaxHumanFilesize', OCP\Util::humanFileSize($maxUploadFilesize)); $folder->assign('allowZipDownload', intval(OCP\Config::getSystemValue('allowZipDownload', true))); $folder->assign('usedSpacePercent', 0); $tmpl->assign('folder', $folder->fetchPage()); $allowZip = OCP\Config::getSystemValue('allowZipDownload', true) && $totalSize <= OCP\Config::getSystemValue('maxZipInputSize', OCP\Util::computerFileSize('800 MB')); $tmpl->assign('allowZipDownload', intval($allowZip)); $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=' . urlencode($getPath)); } else { $tmpl->assign('dir', $dir); // Show file preview if viewer is available if ($type == 'file') { $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download'); } else { $tmpl->assign('downloadURL', OCP\Util::linkToPublic('files') . $urlLinkIdentifiers . '&download&path=' . urlencode($getPath)); } } $tmpl->printPage(); } exit; } else {
/** * @brief calculates the maximum upload size respecting system settings, free space and user quota * * @param $dir the current folder where the user currently operates * @return number of bytes representing */ public static function maxUploadFilesize($dir) { $upload_max_filesize = OCP\Util::computerFileSize(ini_get('upload_max_filesize')); $post_max_size = OCP\Util::computerFileSize(ini_get('post_max_size')); $freeSpace = \OC\Files\Filesystem::free_space($dir); if ((int) $upload_max_filesize === 0 and (int) $post_max_size === 0) { $maxUploadFilesize = \OC\Files\SPACE_UNLIMITED; } elseif ((int) $upload_max_filesize === 0 or (int) $post_max_size === 0) { $maxUploadFilesize = max($upload_max_filesize, $post_max_size); //only the non 0 value counts } else { $maxUploadFilesize = min($upload_max_filesize, $post_max_size); } if ($freeSpace !== \OC\Files\SPACE_UNKNOWN) { $freeSpace = max($freeSpace, 0); return min($maxUploadFilesize, $freeSpace); } else { return $maxUploadFilesize; } }