当前位置: 首页>>代码示例>>PHP>>正文


PHP OC_Helper::computerFileSize方法代码示例

本文整理汇总了PHP中OC_Helper::computerFileSize方法的典型用法代码示例。如果您正苦于以下问题:PHP OC_Helper::computerFileSize方法的具体用法?PHP OC_Helper::computerFileSize怎么用?PHP OC_Helper::computerFileSize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在OC_Helper的用法示例。


在下文中一共展示了OC_Helper::computerFileSize方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testComputerFileSize

 function testComputerFileSize()
 {
     $result = OC_Helper::computerFileSize("0 B");
     $expected = '0.0';
     $this->assertEquals($result, $expected);
     $result = OC_Helper::computerFileSize("1 kB");
     $expected = '1024.0';
     $this->assertEquals($result, $expected);
     $result = OC_Helper::computerFileSize("9.5 MB");
     $expected = '9961472.0';
     $this->assertEquals($result, $expected);
     $result = OC_Helper::computerFileSize("465.7 GB");
     $expected = '500041567436.8';
     $this->assertEquals($result, $expected);
 }
开发者ID:ryanshoover,项目名称:core,代码行数:15,代码来源:helper.php

示例2: getQuota

 /**
  * get the quota for the current user
  * @return int
  */
 private function getQuota()
 {
     if ($this->userQuota != -1) {
         return $this->userQuota;
     }
     $userQuota = OC_Preferences::getValue(OC_User::getUser(), 'files', 'quota', 'default');
     if ($userQuota == 'default') {
         $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none');
     }
     if ($userQuota == 'none') {
         $this->userQuota = 0;
     } else {
         $this->userQuota = OC_Helper::computerFileSize($userQuota);
     }
     return $this->userQuota;
 }
开发者ID:noci2012,项目名称:owncloud,代码行数:20,代码来源:quota.php

示例3: getQuota

 /**
  * get the quota for the user
  * @param user
  * @return int
  */
 private function getQuota($user)
 {
     if (in_array($user, $this->userQuota)) {
         return $this->userQuota[$user];
     }
     $userQuota = OC_Preferences::getValue($user, 'files', 'quota', 'default');
     if ($userQuota == 'default') {
         $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none');
     }
     if ($userQuota == 'none') {
         $this->userQuota[$user] = -1;
     } else {
         $this->userQuota[$user] = OC_Helper::computerFileSize($userQuota);
     }
     return $this->userQuota[$user];
 }
开发者ID:CDN-Sparks,项目名称:owncloud,代码行数:21,代码来源:quota.php

示例4: setUploadLimit

 /**
  * set the maximum upload size limit for apache hosts using .htaccess
  *
  * @param int $size file size in bytes
  * @param array $files override '.htaccess' and '.user.ini' locations
  * @return bool false on failure, size on success
  */
 public static function setUploadLimit($size, $files = [])
 {
     //don't allow user to break his config
     $size = intval($size);
     if ($size < self::UPLOAD_MIN_LIMIT_BYTES) {
         return false;
     }
     $size = OC_Helper::phpFileSize($size);
     $phpValueKeys = array('upload_max_filesize', 'post_max_size');
     // default locations if not overridden by $files
     $files = array_merge(['.htaccess' => OC::$SERVERROOT . '/.htaccess', '.user.ini' => OC::$SERVERROOT . '/.user.ini'], $files);
     $updateFiles = [$files['.htaccess'] => ['pattern' => '/php_value %1$s (\\S)*/', 'setting' => 'php_value %1$s %2$s'], $files['.user.ini'] => ['pattern' => '/%1$s=(\\S)*/', 'setting' => '%1$s=%2$s']];
     $success = true;
     foreach ($updateFiles as $filename => $patternMap) {
         // suppress warnings from fopen()
         $handle = @fopen($filename, 'r+');
         if (!$handle) {
             \OCP\Util::writeLog('files', 'Can\'t write upload limit to ' . $filename . '. Please check the file permissions', \OCP\Util::WARN);
             $success = false;
             continue;
             // try to update as many files as possible
         }
         $content = '';
         while (!feof($handle)) {
             $content .= fread($handle, 1000);
         }
         foreach ($phpValueKeys as $key) {
             $pattern = vsprintf($patternMap['pattern'], [$key]);
             $setting = vsprintf($patternMap['setting'], [$key, $size]);
             $hasReplaced = 0;
             $newContent = preg_replace($pattern, $setting, $content, 1, $hasReplaced);
             if ($newContent !== null) {
                 $content = $newContent;
             }
             if ($hasReplaced === 0) {
                 $content .= "\n" . $setting;
             }
         }
         // write file back
         ftruncate($handle, 0);
         rewind($handle);
         fwrite($handle, $content);
         fclose($handle);
     }
     if ($success) {
         return OC_Helper::computerFileSize($size);
     }
     return false;
 }
开发者ID:rosarion,项目名称:core,代码行数:56,代码来源:files.php

示例5: computerFileSize

 /**
  * Make a computer file size (2 kB to 2048)
  * @param string $str file size in a fancy format
  * @return int a file size in bytes
  *
  * Inspired by: http://www.php.net/manual/en/function.filesize.php#92418
  * @since 4.0.0
  */
 public static function computerFileSize($str)
 {
     return \OC_Helper::computerFileSize($str);
 }
开发者ID:enoch85,项目名称:owncloud-testserver,代码行数:12,代码来源:util.php

示例6: setUploadLimit

 /**
  * set the maximum upload size limit for apache hosts using .htaccess
  * @param int size filesisze in bytes
  * @return false on failure, size on success
  */
 static function setUploadLimit($size)
 {
     //don't allow user to break his config -- upper boundary
     if ($size > PHP_INT_MAX) {
         //max size is always 1 byte lower than computerFileSize returns
         if ($size > PHP_INT_MAX + 1) {
             return false;
         }
         $size -= 1;
     } else {
         $size = OC_Helper::humanFileSize($size);
         $size = substr($size, 0, -1);
         //strip the B
         $size = str_replace(' ', '', $size);
         //remove the space between the size and the postfix
     }
     //don't allow user to break his config -- broken or malicious size input
     if (intval($size) == 0) {
         return false;
     }
     $htaccess = @file_get_contents(OC::$SERVERROOT . '/.htaccess');
     //supress errors in case we don't have permissions for
     if (!$htaccess) {
         return false;
     }
     $phpValueKeys = array('upload_max_filesize', 'post_max_size');
     foreach ($phpValueKeys as $key) {
         $pattern = '/php_value ' . $key . ' (\\S)*/';
         $setting = 'php_value ' . $key . ' ' . $size;
         $hasReplaced = 0;
         $content = preg_replace($pattern, $setting, $htaccess, 1, $hasReplaced);
         if ($content !== NULL) {
             $htaccess = $content;
         }
         if ($hasReplaced == 0) {
             $htaccess .= "\n" . $setting;
         }
     }
     //supress errors in case we don't have permissions for it
     if (@file_put_contents(OC::$SERVERROOT . '/.htaccess', $htaccess)) {
         return OC_Helper::computerFileSize($size);
     }
     return false;
 }
开发者ID:jaeindia,项目名称:ownCloud-Enhancements,代码行数:49,代码来源:files.php

示例7: isset

 *
 * You should have received a copy of the GNU Affero General Public License, version 3,
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 *
 */
OC_JSON::checkSubAdminUser();
OCP\JSON::callCheck();
$username = isset($_POST["username"]) ? (string) $_POST["username"] : '';
if ($username === '' && !OC_User::isAdminUser(OC_User::getUser()) || !OC_User::isAdminUser(OC_User::getUser()) && !OC_SubAdmin::isUserAccessible(OC_User::getUser(), $username)) {
    $l = \OC::$server->getL10N('core');
    OC_JSON::error(array('data' => array('message' => $l->t('Authentication error'))));
    exit;
}
//make sure the quota is in the expected format
$quota = (string) $_POST["quota"];
if ($quota !== 'none' and $quota !== 'default') {
    $quota = OC_Helper::computerFileSize($quota);
    $quota = OC_Helper::humanFileSize($quota);
}
// Return Success story
if ($username) {
    \OC::$server->getConfig()->setUserValue($username, 'files', 'quota', $quota);
} else {
    //set the default quota when no username is specified
    if ($quota === 'default') {
        //'default' as default quota makes no sense
        $quota = 'none';
    }
    OC_Appconfig::setValue('files', 'default_quota', $quota);
}
OC_JSON::success(array("data" => array("username" => $username, 'quota' => $quota)));
开发者ID:samj1912,项目名称:repo,代码行数:31,代码来源:setquota.php

示例8: setUploadLimit

 /**
  * set the maximum upload size limit for apache hosts using .htaccess
  *
  * @param int $size file size in bytes
  * @return bool false on failure, size on success
  */
 static function setUploadLimit($size)
 {
     //don't allow user to break his config -- upper boundary
     if ($size > PHP_INT_MAX) {
         //max size is always 1 byte lower than computerFileSize returns
         if ($size > PHP_INT_MAX + 1) {
             return false;
         }
         $size -= 1;
     } else {
         $size = OC_Helper::phpFileSize($size);
     }
     //don't allow user to break his config -- broken or malicious size input
     if (intval($size) === 0) {
         return false;
     }
     //suppress errors in case we don't have permissions for
     $htaccess = @file_get_contents(OC::$SERVERROOT . '/.htaccess');
     if (!$htaccess) {
         return false;
     }
     $phpValueKeys = array('upload_max_filesize', 'post_max_size');
     foreach ($phpValueKeys as $key) {
         $pattern = '/php_value ' . $key . ' (\\S)*/';
         $setting = 'php_value ' . $key . ' ' . $size;
         $hasReplaced = 0;
         $content = preg_replace($pattern, $setting, $htaccess, 1, $hasReplaced);
         if ($content !== null) {
             $htaccess = $content;
         }
         if ($hasReplaced === 0) {
             $htaccess .= "\n" . $setting;
         }
     }
     //check for write permissions
     if (is_writable(OC::$SERVERROOT . '/.htaccess')) {
         file_put_contents(OC::$SERVERROOT . '/.htaccess', $htaccess);
         return OC_Helper::computerFileSize($size);
     } else {
         OC_Log::write('files', 'Can\'t write upload limit to ' . OC::$SERVERROOT . '/.htaccess. Please check the file permissions', OC_Log::WARN);
     }
     return false;
 }
开发者ID:olucao,项目名称:owncloud-core,代码行数:49,代码来源:files.php

示例9: getUserQuota

 /**
  * Get the quota of a user
  *
  * @param string $user
  * @return int Quota bytes
  */
 public static function getUserQuota($user)
 {
     $config = \OC::$server->getConfig();
     $userQuota = $config->getUserValue($user, 'files', 'quota', 'default');
     if ($userQuota === 'default') {
         $userQuota = $config->getAppValue('files', 'default_quota', 'none');
     }
     if ($userQuota === 'none') {
         return \OCP\Files\FileInfo::SPACE_UNLIMITED;
     } else {
         return OC_Helper::computerFileSize($userQuota);
     }
 }
开发者ID:pinoniq,项目名称:core,代码行数:19,代码来源:util.php

示例10: testComputerFileSize

 /**
  * @dataProvider providesComputerFileSize
  */
 function testComputerFileSize($expected, $input)
 {
     $result = OC_Helper::computerFileSize($input);
     $this->assertEquals($expected, $result);
 }
开发者ID:reverserob,项目名称:core,代码行数:8,代码来源:helper.php

示例11: array

$breadcrumb = array();
$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 OC_Template("files", "part.list", "");
$list->assign("files", $files);
$list->assign("baseURL", OC_Helper::linkTo("files", "index.php") . "?dir=");
$list->assign("downloadURL", OC_Helper::linkTo("files", "download.php") . "?file=");
$breadcrumbNav = new OC_Template("files", "part.breadcrumb", "");
$breadcrumbNav->assign("breadcrumb", $breadcrumb);
$breadcrumbNav->assign("baseURL", OC_Helper::linkTo("files", "index.php") . "?dir=");
$upload_max_filesize = OC_Helper::computerFileSize(ini_get('upload_max_filesize'));
$post_max_size = OC_Helper::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 OC_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', OC_Helper::humanFileSize($maxUploadFilesize));
$tmpl->printPage();
开发者ID:shimogapradeep,项目名称:acceptance-testing,代码行数:31,代码来源:Demo+Code+-+PHP.php

示例12: getUserQuota

 public static function getUserQuota($user)
 {
     $userQuota = OC_Preferences::getValue($user, 'files', 'quota', 'default');
     if ($userQuota === 'default') {
         $userQuota = OC_AppConfig::getValue('files', 'default_quota', 'none');
     }
     if ($userQuota === 'none') {
         return \OC\Files\SPACE_UNLIMITED;
     } else {
         return OC_Helper::computerFileSize($userQuota);
     }
 }
开发者ID:hjimmy,项目名称:owncloud,代码行数:12,代码来源:util.php

示例13: getUserQuota

 /**
  * Get the quota of a user
  *
  * @param string $user
  * @return int Quota bytes
  */
 public static function getUserQuota($user)
 {
     $userQuota = \OC::$server->getUserManager()->get($user)->getQuota();
     if ($userQuota === 'none') {
         return \OCP\Files\FileInfo::SPACE_UNLIMITED;
     } else {
         return OC_Helper::computerFileSize($userQuota);
     }
 }
开发者ID:drognisep,项目名称:Portfolio-Site,代码行数:15,代码来源:util.php

示例14: array

<?php

// Init owncloud
require_once '../../lib/base.php';
OC_JSON::checkAdminUser();
$username = $_POST["username"];
$quota = OC_Helper::computerFileSize($_POST["quota"]);
// Return Success story
OC_Preferences::setValue($username, 'files', 'quota', $quota);
OC_JSON::success(array("data" => array("username" => $username, 'quota' => $quota)));
开发者ID:Teino1978-Corp,项目名称:Teino1978-Corp-owncloud_.htaccess-,代码行数:10,代码来源:owncloud_settings_ajax_setquota.php


注:本文中的OC_Helper::computerFileSize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。