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


PHP File::format_size方法代码示例

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


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

示例1: validate

 /**
  * Run through the rules for this validator checking against
  * the temporary file set by {@link setTmpFile()} to see if
  * the file is deemed valid or not.
  * 
  * @return boolean
  */
 public function validate()
 {
     // we don't validate for empty upload fields yet
     if (!isset($this->tmpFile['name']) || empty($this->tmpFile['name'])) {
         return true;
     }
     $isRunningTests = class_exists('SapphireTest', false) && SapphireTest::is_running_test();
     //needed to allow XHR uploads
     /*if(isset($this->tmpFile['tmp_name']) && !is_uploaded_file($this->tmpFile['tmp_name']) && !$isRunningTests) {
     			$this->errors[] = _t('File.NOVALIDUPLOAD', 'File is not a valid upload');
     			return false;
     		}*/
     $pathInfo = pathinfo($this->tmpFile['name']);
     // filesize validation
     if (!$this->isValidSize()) {
         $ext = isset($pathInfo['extension']) ? $pathInfo['extension'] : '';
         $arg = File::format_size($this->getAllowedMaxFileSize($ext));
         $this->errors[] = sprintf(_t('File.TOOLARGE', 'Filesize is too large, maximum %s allowed.', PR_MEDIUM, 'Argument 1: Filesize (e.g. 1MB)'), $arg);
         return false;
     }
     // extension validation
     if (!$this->isValidExtension()) {
         $this->errors[] = sprintf(_t('File.INVALIDEXTENSION', 'Extension is not allowed (valid: %s)', PR_MEDIUM, 'Argument 1: Comma-separated list of valid extensions'), wordwrap(implode(', ', $this->allowedExtensions)));
         return false;
     }
     return true;
 }
开发者ID:helpfulrobot,项目名称:burnbright-silverstripe-ajaxuploadfield,代码行数:34,代码来源:XHRUpload.php

示例2: testFormatSize

 /**
  * Test the File::format_size() method
  */
 function testFormatSize()
 {
     $this->assertEquals("1000 bytes", File::format_size(1000));
     $this->assertEquals("1023 bytes", File::format_size(1023));
     $this->assertEquals("1 KB", File::format_size(1025));
     $this->assertEquals("9.8 KB", File::format_size(10000));
     $this->assertEquals("49 KB", File::format_size(50000));
     $this->assertEquals("977 KB", File::format_size(1000000));
     $this->assertEquals("1 MB", File::format_size(1024 * 1024));
     $this->assertEquals("954 MB", File::format_size(1000000000));
     $this->assertEquals("1 GB", File::format_size(1024 * 1024 * 1024));
     $this->assertEquals("9.3 GB", File::format_size(10000000000.0));
     // It use any denomination higher than GB.  It also doesn't overflow with >32 bit integers
     $this->assertEquals("93132.3 GB", File::format_size(100000000000000.0));
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:18,代码来源:FileTest.php

示例3: Field

 public function Field($properties = array())
 {
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
     Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/ssui.core.js');
     Requirements::add_i18n_javascript(FRAMEWORK_DIR . '/javascript/lang');
     // Avoid conflicts
     Requirements::block(FRAMEWORK_DIR . '/javascript/UploadField_uploadtemplate.js');
     Requirements::block(FRAMEWORK_DIR . '/javascript/UploadField_downloadtemplate.js');
     Requirements::block(FRAMEWORK_DIR . '/javascript/UploadField.js');
     Requirements::combine_files('frontenduploadfield.js', array(THIRDPARTY_DIR . '/javascript-templates/tmpl.js', THIRDPARTY_DIR . '/javascript-loadimage/load-image.js', THIRDPARTY_DIR . '/jquery-fileupload/jquery.iframe-transport.js', THIRDPARTY_DIR . '/jquery-fileupload/cors/jquery.xdr-transport.js', THIRDPARTY_DIR . '/jquery-fileupload/jquery.fileupload.js', THIRDPARTY_DIR . '/jquery-fileupload/jquery.fileupload-ui.js', FORM_EXTRAS_PATH . '/javascript/uploadfield/FrontendUploadField_uploadtemplate.js', FORM_EXTRAS_PATH . '/javascript/uploadfield/FrontendUploadField_downloadtemplate.js', FORM_EXTRAS_PATH . '/javascript/uploadfield/FrontendUploadField.js'));
     Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
     // TODO hmmm, remove it?
     Requirements::css(FRAMEWORK_DIR . '/css/UploadField.css');
     // Calculated config as per jquery.fileupload-ui.js
     $allowedMaxFileNumber = $this->getAllowedMaxFileNumber();
     $config = array('url' => $this->Link('upload'), 'urlSelectDialog' => $this->Link('select'), 'urlAttach' => $this->Link('attach'), 'urlFileExists' => $this->link('fileexists'), 'acceptFileTypes' => '.+$', 'maxNumberOfFiles' => $allowedMaxFileNumber ? $allowedMaxFileNumber - count($this->getItemIDs()) : null);
     // Validation: File extensions
     if ($allowedExtensions = $this->getAllowedExtensions()) {
         $config['acceptFileTypes'] = '(\\.|\\/)(' . implode('|', $allowedExtensions) . ')$';
         $config['errorMessages']['acceptFileTypes'] = _t('File.INVALIDEXTENSIONSHORT', 'Extension is not allowed');
     }
     // Validation: File size
     if ($allowedMaxFileSize = $this->getValidator()->getAllowedMaxFileSize()) {
         $config['maxFileSize'] = $allowedMaxFileSize;
         $config['errorMessages']['maxFileSize'] = _t('File.TOOLARGESHORT', 'Filesize exceeds {size}', array('size' => File::format_size($config['maxFileSize'])));
     }
     // Validation: Number of files
     if ($allowedMaxFileNumber) {
         if ($allowedMaxFileNumber > 1) {
             $config['errorMessages']['maxNumberOfFiles'] = _t('UploadField.MAXNUMBEROFFILESSHORT', 'Can only upload {count} files', array('count' => $allowedMaxFileNumber));
         } else {
             $config['errorMessages']['maxNumberOfFiles'] = _t('UploadField.MAXNUMBEROFFILESONE', 'Can only upload one file');
         }
     }
     //get all the existing files in the current folder
     if ($this->getOverwriteWarning()) {
         //add overwrite warning error message to the config object sent to Javascript
         $config['errorMessages']['overwriteWarning'] = _t('UploadField.OVERWRITEWARNING', 'File with the same name already exists');
     }
     $mergedConfig = array_merge($config, $this->ufConfig);
     return $this->customise(array('configString' => str_replace('"', """, Convert::raw2json($mergedConfig)), 'config' => new ArrayData($mergedConfig), 'multiple' => $allowedMaxFileNumber !== 1))->renderWith($this->getTemplates());
 }
开发者ID:helpfulrobot,项目名称:lekoala-silverstripe-form-extras,代码行数:44,代码来源:FrontendUploadField.php

示例4: Field

 public function Field($properties = array())
 {
     $record = $this->getRecord();
     $name = $this->getName();
     // if there is a has_one relation with that name on the record and
     // allowedMaxFileNumber has not been set, it's wanted to be 1
     if ($record && $record->exists() && $record->has_one($name) && !$this->getConfig('allowedMaxFileNumber')) {
         $this->setConfig('allowedMaxFileNumber', 1);
     }
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-ui/jquery-ui.js');
     Requirements::javascript(THIRDPARTY_DIR . '/jquery-entwine/dist/jquery.entwine-dist.js');
     Requirements::javascript(FRAMEWORK_DIR . '/javascript/i18n.js');
     Requirements::javascript(FRAMEWORK_ADMIN_DIR . '/javascript/ssui.core.js');
     Requirements::combine_files('uploadfield.js', array(THIRDPARTY_DIR . '/javascript-templates/tmpl.js', THIRDPARTY_DIR . '/javascript-loadimage/load-image.js', THIRDPARTY_DIR . '/jquery-fileupload/jquery.iframe-transport.js', THIRDPARTY_DIR . '/jquery-fileupload/cors/jquery.xdr-transport.js', THIRDPARTY_DIR . '/jquery-fileupload/jquery.fileupload.js', THIRDPARTY_DIR . '/jquery-fileupload/jquery.fileupload-ui.js', FRAMEWORK_DIR . '/javascript/UploadField_uploadtemplate.js', FRAMEWORK_DIR . '/javascript/UploadField_downloadtemplate.js', FRAMEWORK_DIR . '/javascript/UploadField.js'));
     Requirements::javascript(THIRDPARTY_DIR . '/jquery/jquery.js');
     // Requirements::javascript('gallery/javascript/GalleryUploadField.js');
     Requirements::css(THIRDPARTY_DIR . '/jquery-ui-themes/smoothness/jquery-ui.css');
     // TODO hmmm, remove it?
     Requirements::css(FRAMEWORK_DIR . '/css/UploadField.css');
     // Requirements::css('gallery/css/GalleryUploadField.css');
     $allowedMaxFileNumber = $this->getAllowedMaxFileNumber();
     $config = array('url' => $this->Link('upload'), 'urlSelectDialog' => $this->Link('select'), 'urlAttach' => $this->Link('attach'), 'urlSort' => $this->Link('sort'), 'urlFileExists' => $this->link('fileexists'), 'acceptFileTypes' => '.+$', 'maxNumberOfFiles' => $allowedMaxFileNumber ? $allowedMaxFileNumber - count($this->getItemIDs()) : null);
     if (count($this->getValidator()->getAllowedExtensions())) {
         $allowedExtensions = $this->getValidator()->getAllowedExtensions();
         $config['acceptFileTypes'] = '(\\.|\\/)(' . implode('|', $allowedExtensions) . ')$';
         $config['errorMessages']['acceptFileTypes'] = _t('File.INVALIDEXTENSIONSHORT', 'Extension is not allowed');
     }
     if ($this->getValidator()->getAllowedMaxFileSize()) {
         $config['maxFileSize'] = $this->getValidator()->getAllowedMaxFileSize();
         $config['errorMessages']['maxFileSize'] = _t('File.TOOLARGESHORT', 'Filesize exceeds {size}', array('size' => File::format_size($config['maxFileSize'])));
     }
     if ($config['maxNumberOfFiles'] > 1) {
         $config['errorMessages']['maxNumberOfFiles'] = _t('UploadField.MAXNUMBEROFFILESSHORT', 'Can only upload {count} files', array('count' => $config['maxNumberOfFiles']));
     }
     $configOverwrite = array();
     if (is_numeric($config['maxNumberOfFiles']) && $this->getItems()->count()) {
         $configOverwrite['maxNumberOfFiles'] = $config['maxNumberOfFiles'] - $this->getItems()->count();
     }
     $config = array_merge($config, $this->ufConfig, $configOverwrite);
     return $this->customise(array('configString' => str_replace('"', """, Convert::raw2json($config)), 'config' => new ArrayData($config), 'multiple' => $config['maxNumberOfFiles'] !== 1, 'displayInput' => !isset($configOverwrite['maxNumberOfFiles']) || $configOverwrite['maxNumberOfFiles']))->renderWith($this->getTemplates());
 }
开发者ID:vinstah,项目名称:body,代码行数:42,代码来源:GalleryUploadField.php

示例5: optimizeImage

 /**
  * optimize a single image and return a
  * json array
  * @return json
  */
 public function optimizeImage()
 {
     $krakenService = new KrakenService();
     $response = array();
     if ($this->owner->request->getVar('ID') >= 1) {
         $image = Image::get()->byID(intval($this->owner->request->getVar('ID')));
     }
     //check if a file path was supplied
     if ($image) {
         //optimize this image
         if (!$image->Kraked) {
             $data = $krakenService->optimizeImage($image->getFullPath());
             //check if optimization was success
             if ($data['success'] && $data['saved_bytes'] >= 0) {
                 //attempt to download the kraked file
                 $krakedFile = $krakenService->getOptimizedImage($data['kraked_url']);
                 //update the file
                 if ($krakedFile) {
                     file_put_contents($image, $krakedFile);
                     $image->Kraked = true;
                     $image->write();
                     $response['Name'] = $data['file_name'];
                     $response['UnoptimizedSize'] = File::format_size($data['original_size']);
                     $response['OptimizedSize'] = File::format_size($data['kraked_size']);
                 }
             }
         }
         $resizedImageCount = $this->optimizeFormattedImages($image);
         $response['FormattedImagesMessage'] = "Optimzed {$resizedImageCount} formatted images";
         if (Director::is_ajax()) {
             return json_encode($response);
         } else {
             $message = _t('Kraken.OPTIMIZED', '_Optimized');
             $this->owner->getResponse()->addHeader('X-Status', rawurlencode($message));
             return;
         }
     }
 }
开发者ID:rsmclaren,项目名称:silverstripe-kraken,代码行数:43,代码来源:KrakenAssetAdminExtension.php

示例6: getSizeForHuman

 /**
  * Generate a human friendly reprensetation of the size of this S3file
  * @return string
  */
 public function getSizeForHuman()
 {
     return File::format_size($this->Size);
 }
开发者ID:firebrandhq,项目名称:s3fileupload,代码行数:8,代码来源:S3File.php

示例7: getSize

 /**
  * @return bool|string
  */
 public function getSize()
 {
     return $this->FileSize ? File::format_size($this->FileSize) : false;
 }
开发者ID:helpfulrobot,项目名称:mademedia-silverstripe-cloudinary,代码行数:7,代码来源:CloudinaryFile.php

示例8: getSize

 /**
  * Returns the size of the file type in an appropriate format.
  *
  * @return string|false String value, or false if doesn't exist
  */
 public function getSize()
 {
     $size = $this->getAbsoluteSize();
     if ($size) {
         return \File::format_size($size);
     }
     return false;
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:13,代码来源:DBFile.php

示例9: validate

	/**
	 * Container for all validation on the file
	 * (e.g. size and extension restrictions).
	 * Is NOT connected to the {Validator} classes,
	 * please have a look at {FileField->validate()}
	 * for an example implementation of external validation.
	 *
	 * @param array $tmpFile
	 * @return boolean
	 */
	public function validate($tmpFile) {
		// we don't validate for empty upload fields yet
		if(!isset($tmpFile['name']) || empty($tmpFile['name'])) return true;

		$pathInfo = pathinfo($tmpFile['name']);
		// filesize validation
		if(!$this->isValidSize($tmpFile)) {
			$this->errors[] = sprintf(
				_t(
					'File.TOOLARGE', 
					'Filesize is too large, maximum %s allowed.',
					PR_MEDIUM,
					'Argument 1: Filesize (e.g. 1MB)'
				),
				File::format_size($this->getAllowedMaxFileSize($pathInfo['extension']))
			);
			return false;
		}

		// extension validation
		if(!$this->isValidExtension($tmpFile)) {
			$this->errors[] = sprintf(
				_t(
					'File.INVALIDEXTENSION', 
					'Extension is not allowed (valid: %s)',
					PR_MEDIUM,
					'Argument 1: Comma-separated list of valid extensions'
				),
				implode(',',$this->allowedExtensions)
			);
			return false;
		}
		
		return true;
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:45,代码来源:Upload.php

示例10: UploadLimit

 /**
  * Return the upload limit for snapshot uploads
  * @return string
  */
 public function UploadLimit()
 {
     return File::format_size(min(File::ini2bytes(ini_get('upload_max_filesize')), File::ini2bytes(ini_get('post_max_size'))));
 }
开发者ID:udomsak,项目名称:deploynaut,代码行数:8,代码来源:DNRoot.php

示例11: getSize

 function getSize()
 {
     $size = $this->getAbsoluteSize();
     return $size ? File::format_size($size) : false;
 }
开发者ID:nyeholt,项目名称:silverstripe-dms,代码行数:5,代码来源:DMSDocument.php

示例12: Size

 public function Size()
 {
     $size = $this->owner->FileSize;
     return $size ? File::format_size($size) : false;
 }
开发者ID:stephenmcm,项目名称:silverstripe-cdncontent,代码行数:5,代码来源:CDNFile.php

示例13: uploadsnapshot

 /**
  * Action
  * 
  * @return string - HTML
  */
 public function uploadsnapshot(SS_HTTPRequest $request)
 {
     // Performs canView permission check by limiting visible projects
     $project = $this->getCurrentProject();
     if (!$project) {
         return new SS_HTTPResponse("Project '" . Convert::raw2xml($request->latestParam('Project')) . "' not found.", 404);
     }
     if (!$project->canUploadArchive()) {
         return new SS_HTTPResponse("Not allowed to upload", 401);
     }
     return $this->customise(array('Project' => $project, 'CurrentProject' => $project, 'SnapshotsSection' => 1, 'UploadLimit' => $maxSize = File::format_size(min(File::ini2bytes(ini_get('upload_max_filesize')), File::ini2bytes(ini_get('post_max_size')))), 'UploadSnapshotForm' => $this->getUploadSnapshotForm($request), 'PostSnapshotForm' => $this->getPostSnapshotForm($request)))->renderWith(array('DNRoot_uploadsnapshot', 'DNRoot'));
 }
开发者ID:adrexia,项目名称:deploynaut,代码行数:17,代码来源:DNRoot.php

示例14: validate

 /**
  * Run through the rules for this validator checking against
  * the temporary file set by {@link setTmpFile()} to see if
  * the file is deemed valid or not.
  *
  * @return boolean
  */
 public function validate()
 {
     // we don't validate for empty upload fields yet
     if (empty($this->tmpFile['name'])) {
         return true;
     }
     // Check file upload
     if (!$this->isValidUpload()) {
         $this->errors[] = _t('File.NOVALIDUPLOAD', 'File is not a valid upload');
         return false;
     }
     // Check file isn't empty
     if ($this->isFileEmpty()) {
         $this->errors[] = _t('File.NOFILESIZE', 'Filesize is zero bytes.');
         return false;
     }
     // filesize validation
     if (!$this->isValidSize()) {
         $pathInfo = pathinfo($this->tmpFile['name']);
         $ext = isset($pathInfo['extension']) ? $pathInfo['extension'] : '';
         $arg = File::format_size($this->getAllowedMaxFileSize($ext));
         $this->errors[] = _t('File.TOOLARGE', 'Filesize is too large, maximum {size} allowed', 'Argument 1: Filesize (e.g. 1MB)', array('size' => $arg));
         return false;
     }
     // extension validation
     if (!$this->isValidExtension()) {
         $this->errors[] = _t('File.INVALIDEXTENSION_SHORT', 'Extension is not allowed');
         return false;
     }
     return true;
 }
开发者ID:SpiritLevel,项目名称:silverstripe-framework,代码行数:38,代码来源:Upload_Validator.php

示例15: validate

 /**
  * Looser check validation that doesn't do is_upload_file()
  * checks as we're faking a POST request that PHP didn't generate
  * itself.
  *
  * @return boolean
  */
 public function validate()
 {
     $pathInfo = pathinfo($this->tmpFile['name']);
     // filesize validation
     if (!$this->isValidSize()) {
         $ext = isset($pathInfo['extension']) ? $pathInfo['extension'] : '';
         $arg = File::format_size($this->getAllowedMaxFileSize($ext));
         $this->errors[] = _t('File.TOOLARGE', 'Filesize is too large, maximum {size} allowed', 'Argument 1: Filesize (e.g. 1MB)', array('size' => $arg));
         return false;
     }
     // extension validation
     if (!$this->isValidExtension()) {
         $this->errors[] = _t('File.INVALIDEXTENSION', 'Extension is not allowed (valid: {extensions})', 'Argument 1: Comma-separated list of valid extensions', array('extensions' => implode(',', $this->allowedExtensions)));
         return false;
     }
     return true;
 }
开发者ID:assertchris,项目名称:silverstripe-framework,代码行数:24,代码来源:UploadTest.php


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