當前位置: 首頁>>代碼示例>>PHP>>正文


PHP OC_Helper::phpFileSize方法代碼示例

本文整理匯總了PHP中OC_Helper::phpFileSize方法的典型用法代碼示例。如果您正苦於以下問題:PHP OC_Helper::phpFileSize方法的具體用法?PHP OC_Helper::phpFileSize怎麽用?PHP OC_Helper::phpFileSize使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在OC_Helper的用法示例。


在下文中一共展示了OC_Helper::phpFileSize方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: 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

示例2: 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

示例3: testPhpFileSize

 /**
  * @dataProvider phpFileSizeProvider
  */
 public function testPhpFileSize($expected, $input)
 {
     $result = OC_Helper::phpFileSize($input);
     $this->assertEquals($expected, $result);
 }
開發者ID:reverserob,項目名稱:core,代碼行數:8,代碼來源:helper.php


注:本文中的OC_Helper::phpFileSize方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。