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


PHP IOHelper::getFileSize方法代码示例

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


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

示例1: getSize

 /**
  * @return mixed
  */
 public function getSize()
 {
     if (!$this->_size) {
         $this->_size = IOHelper::getFileSize($this->getRealPath());
     }
     return $this->_size;
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:10,代码来源:File.php

示例2: processLogs

 /**
  * Saves log messages in files.
  *
  * @param array $logs list of log messages
  */
 protected function processLogs($logs)
 {
     $logFile = IOHelper::normalizePathSeparators($this->getLogPath() . '/' . $this->getLogFile());
     if (IOHelper::getFileSize($logFile) > $this->getMaxFileSize() * 1024) {
         $this->rotateFiles();
     }
     $lock = craft()->config->get('useLockWhenWritingToFile') === true;
     $fp = @fopen($logFile, 'a');
     if ($lock) {
         @flock($fp, LOCK_EX);
     }
     foreach ($logs as $log) {
         $message = LoggingHelper::redact($log[0]);
         $level = $log[1];
         $category = $log[2];
         $time = $log[3];
         $force = isset($log[4]) && $log[4] == true ? true : false;
         @fwrite($fp, $this->formatLogMessageWithForce($message, $level, $category, $time, $force));
     }
     @fwrite($fp, PHP_EOL . '******************************************************************************************************' . PHP_EOL);
     if ($lock) {
         @flock($fp, LOCK_UN);
     }
     @fclose($fp);
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:30,代码来源:FileLogRoute.php

示例3: processLogs

 /**
  * Saves log messages in files.
  *
  * @param array $logs The list of log messages
  *
  * @return null
  */
 protected function processLogs($logs)
 {
     $types = array();
     foreach ($logs as $log) {
         $message = LoggingHelper::redact($log[0]);
         $level = $log[1];
         $category = $log[2];
         $time = $log[3];
         $force = isset($log[4]) && $log[4] == true ? true : false;
         $plugin = isset($log[5]) ? StringHelper::toLowerCase($log[5]) : 'craft';
         if (isset($types[$plugin])) {
             $types[$plugin] .= $this->formatLogMessageWithForce($message, $level, $category, $time, $force, $plugin);
         } else {
             $types[$plugin] = $this->formatLogMessageWithForce($message, $level, $category, $time, $force, $plugin);
         }
     }
     foreach ($types as $plugin => $text) {
         $text .= PHP_EOL . '******************************************************************************************************' . PHP_EOL;
         $this->setLogFile($plugin . '.log');
         $logFile = IOHelper::normalizePathSeparators($this->getLogPath() . '/' . $this->getLogFile());
         // Check the config setting first.  Is it set to true?
         if (craft()->config->get('useWriteFileLock') === true) {
             $lock = true;
         } else {
             if (craft()->config->get('useWriteFileLock') === false) {
                 $lock = false;
             } else {
                 if (craft()->cache->get('useWriteFileLock') === 'yes') {
                     $lock = true;
                 } else {
                     $lock = false;
                 }
             }
         }
         $fp = @fopen($logFile, 'a');
         if ($lock) {
             @flock($fp, LOCK_EX);
         }
         if (IOHelper::getFileSize($logFile) > $this->getMaxFileSize() * 1024) {
             $this->rotateFiles();
             if ($lock) {
                 @flock($fp, LOCK_UN);
             }
             @fclose($fp);
             if ($lock) {
                 IOHelper::writeToFile($logFile, $text, false, true, false);
             } else {
                 IOHelper::writeToFile($logFile, $text, false, true, true);
             }
         } else {
             @fwrite($fp, $text);
             if ($lock) {
                 @flock($fp, LOCK_UN);
             }
             @fclose($fp);
         }
     }
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:65,代码来源:FileLogRoute.php

示例4: __construct

 /**
  * Constructor
  *
  * @param null $imagePath
  * @param null $imageUrl
  */
 public function __construct($imagePath = null, $imageUrl = null)
 {
     if ($imagePath != 'null') {
         $this['path'] = $imagePath;
         $imageInfo = @getimagesize($imagePath);
         $this['width'] = $imageInfo[0];
         $this['height'] = $imageInfo[1];
         $this['extension'] = IOHelper::getExtension($imagePath);
         $this['mimeType'] = IOHelper::getMimeType($imagePath);
         $this['size'] = IOHelper::getFileSize($imagePath);
     }
     if ($imageUrl != 'null') {
         $this['url'] = $imageUrl;
     }
 }
开发者ID:martinleveille,项目名称:Imager-Craft,代码行数:21,代码来源:Imager_ImageModel.php

示例5: __construct

 /**
  * Constructor
  *
  * @param null $imagePath
  * @param null $imageUrl
  */
 public function __construct($imagePath = null, $imageUrl = null, $paths = null, $transform = null)
 {
     if ($imagePath != 'null') {
         $this['path'] = $imagePath;
         $this['extension'] = IOHelper::getExtension($imagePath);
         $this['mimeType'] = IOHelper::getMimeType($imagePath);
         $this['size'] = IOHelper::getFileSize($imagePath);
         $imageInfo = @getimagesize($imagePath);
         if (is_array($imageInfo) && $imageInfo[0] !== '' && $imageInfo[1] !== '') {
             $this['width'] = $imageInfo[0];
             $this['height'] = $imageInfo[1];
         } else {
             // Couldn't get size. Calculate size based on source image and transform.
             $sourceImageInfo = @getimagesize($paths->sourcePath . $paths->sourceFilename);
             $sourceSize = new \Imagine\Image\Box($sourceImageInfo[0], $sourceImageInfo[1]);
             $targetCrop = craft()->imager->getCropSize($sourceSize, $transform);
             $this['width'] = $targetCrop->getWidth();
             $this['height'] = $targetCrop->getHeight();
         }
     }
     if ($imageUrl != 'null') {
         $this['url'] = $imageUrl;
     }
 }
开发者ID:aelvan,项目名称:Imager-Craft,代码行数:30,代码来源:Imager_ImageModel.php

示例6: uploadVideo

 /**
  * Create a resumable video upload to YouTube.
  *
  * @param AssetFileModel                $asset
  * @param \Google_Service_YouTube_Video $video
  *
  * @throws Exception
  *
  * @return bool|string
  */
 protected function uploadVideo(AssetFileModel $asset, \Google_Service_YouTube_Video $video)
 {
     // Get file by asset
     $file = $this->getAssetFile($asset);
     // Specify the size of each chunk of data, in bytes. Set a higher value for
     // reliable connection as fewer chunks lead to faster uploads. Set a lower
     // value for better recovery on less reliable connections.
     $chunkSizeBytes = 1 * 1024 * 1024;
     // Verify the client
     if ($this->client instanceof \Google_Client) {
         // Setting the defer flag to true tells the client to return a request which can be called
         // with ->execute(); instead of making the API call immediately.
         $this->client->setDefer(true);
         // Create a request for the API's videos.insert method to create and upload the video.
         $insertRequest = $this->youtube->videos->insert('status,snippet', $video);
         // Create a MediaFileUpload object for resumable uploads.
         $media = new \Google_Http_MediaFileUpload($this->client, $insertRequest, 'video/*', null, true, $chunkSizeBytes);
         $media->setFileSize(IOHelper::getFileSize($file));
         // Read the media file and upload it chunk by chunk.
         $status = $this->uploadChunks($file, $media, $chunkSizeBytes);
         // If you want to make other calls after the file upload, set setDefer back to false
         $this->client->setDefer(false);
         // Return the status
         return $status;
     }
     // Or die
     throw new Exception(Craft::t('Unable to authenticate the YouTube API client'));
 }
开发者ID:boboldehampsink,项目名称:youtube,代码行数:38,代码来源:YouTubeService.php

示例7: getLocalImageSource

 /**
  * Get a local image source to use for transforms.
  *
  * @param $file
  *
  * @throws Exception
  * @return mixed
  */
 public function getLocalImageSource(AssetFileModel $file)
 {
     $sourceType = craft()->assetSources->getSourceTypeById($file->sourceId);
     $imageSourcePath = $sourceType->getImageSourcePath($file);
     if (!IOHelper::fileExists($imageSourcePath) || IOHelper::getFileSize($imageSourcePath) == 0) {
         if (!$sourceType->isRemote()) {
             throw new Exception(Craft::t('Image “{file}” cannot be found.', array('file' => $file->filename)));
         }
         // Delete it just in case it's a 0-byter
         IOHelper::deleteFile($imageSourcePath, true);
         $localCopy = $sourceType->getLocalCopy($file);
         if (!IOHelper::fileExists($localCopy) || IOHelper::getFileSize($localCopy) == 0) {
             throw new Exception(Craft::t('Tried to download the source file for image “{file}”, but it was 0 bytes long.', array('file' => $file->filename)));
         }
         $this->storeLocalSource($localCopy, $imageSourcePath);
         $this->queueSourceForDeletingIfNecessary($imageSourcePath);
         IOHelper::deleteFile($localCopy, true);
     }
     $file->setTransformSource($imageSourcePath);
     return $imageSourcePath;
 }
开发者ID:JulesVan,项目名称:solutions-con,代码行数:29,代码来源:AssetTransformsService.php

示例8: _autoGuessImageQuality

	/**
	 * @param     $tempFileName
	 * @param     $originalSize
	 * @param     $extension
	 * @param     $minQuality
	 * @param     $maxQuality
	 * @param int $step
	 *
	 * @return bool
	 */
	private function _autoGuessImageQuality($tempFileName, $originalSize, $extension, $minQuality, $maxQuality, $step = 0)
	{
		// Give ourselves some extra time.
		@set_time_limit(30);

		if ($step == 0)
		{
			$tempFileName = IOHelper::getFolderName($tempFileName).IOHelper::getFileName($tempFileName, false).'-temp.'.$extension;
		}

		// Find our target quality by splitting the min and max qualities
		$midQuality = (int)ceil($minQuality + (($maxQuality - $minQuality) / 2));

		// Set the min and max acceptable ranges. .10 means anything between 90% and 110% of the original file size is acceptable.
		$acceptableRange = .10;

		clearstatcache();

		// Generate a new temp image and get it's file size.
		$this->_image->save($tempFileName, $this->_getSaveOptions($midQuality, $extension));
		$newFileSize = IOHelper::getFileSize($tempFileName);

		// If we're on step 10 OR we're within our acceptable range threshold OR midQuality = maxQuality (1 == 1),
		// let's use the current image.
		if ($step == 10 || abs(1 - $originalSize / $newFileSize) < $acceptableRange || $midQuality == $maxQuality)
		{
			clearstatcache();

			// Generate one last time.
			$this->_image->save($tempFileName, $this->_getSaveOptions($midQuality));
			return true;
		}

		$step++;

		if ($newFileSize > $originalSize)
		{
			return $this->_autoGuessImageQuality($tempFileName, $originalSize, $extension, $minQuality, $midQuality, $step);
		}
		// Too much.
		else
		{
			return $this->_autoGuessImageQuality($tempFileName, $originalSize, $extension, $midQuality, $maxQuality, $step);
		}
	}
开发者ID:harish94,项目名称:Craft-Release,代码行数:55,代码来源:Image.php

示例9: _uploadFile

 /**
  * Upload a file to Rackspace.
  *
  * @param $targetUri
  * @param $sourceFile
  *
  * @return bool
  */
 private function _uploadFile($targetUri, $sourceFile)
 {
     $fileSize = IOHelper::getFileSize($sourceFile);
     $fp = fopen($sourceFile, "r");
     $headers = array('Content-type: ' . IOHelper::getMimeType($sourceFile), 'Content-length: ' . $fileSize);
     $curlOptions = array(CURLOPT_UPLOAD => true, CURLOPT_INFILE => $fp, CURLOPT_INFILESIZE => $fileSize);
     $targetUri = $this->_prepareRequestURI($this->getSettings()->container, $targetUri);
     $this->_doAuthenticatedRequest(static::RACKSPACE_STORAGE_OPERATION, $targetUri, 'PUT', $headers, $curlOptions);
     fclose($fp);
     return true;
 }
开发者ID:ericnormannn,项目名称:m,代码行数:19,代码来源:RackspaceAssetSourceType.php

示例10: _updateAsset

 private function _updateAsset($asset, $image, $path)
 {
     // Update our model
     $asset->size = IOHelper::getFileSize($path);
     $asset->width = $image->getWidth();
     $asset->height = $image->getHeight();
     // Then, make sure we update the asset info as stored in the database
     $fileRecord = AssetFileRecord::model()->findById($asset->id);
     $fileRecord->size = $asset->size;
     $fileRecord->width = $asset->width;
     $fileRecord->height = $asset->height;
     $fileRecord->dateModified = IOHelper::getLastTimeModified($path);
     $fileRecord->save(false);
 }
开发者ID:kcolls,项目名称:ImageResizer,代码行数:14,代码来源:ImageResizerService.php


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