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


PHP Gdn_Upload::FormatFileSize方法代码示例

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


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

示例1: _checkTable

/**
 *
 *
 * @param $Data
 */
function _checkTable($Data)
{
    echo "<table class='Data' width='100%' style='table-layout: fixed;'>\n";
    echo "<thead><tr><td width='20%'>Field</td><td width='45%'>Current</td><td width='35%'>File</td></tr></thead>";
    $First = true;
    foreach ($Data as $Key => $Value) {
        if (stringBeginsWith($Key, 'File_') || is_array($Value) || $Key == 'Name') {
            continue;
        }
        $Value = Gdn_Format::html($Value);
        $FileValue = Gdn_Format::html(val('File_' . $Key, $Data));
        if ($Key == 'MD5') {
            $Value = substr($Value, 0, 10);
            $FileValue = substr($FileValue, 0, 10);
        }
        if ($Key == 'FileSize') {
            $Value = Gdn_Upload::FormatFileSize($Value);
        }
        echo "<tr><td>{$Key}</td><td>{$Value}</td>";
        if ($Error = val('File_Error', $Data)) {
            if ($First) {
                echo '<td rowspan="4">', htmlspecialchars($Error), '</td>';
            }
        } else {
            echo "<td>{$FileValue}</td></tr>";
        }
        echo "\n";
        $First = false;
    }
    echo '</table>';
}
开发者ID:vanilla,项目名称:community,代码行数:36,代码来源:check.php

示例2: PostController_Upload_Create

 /**
  * PostController_Upload_Create function.
  * 
  * Controller method that allows plugin to handle ajax file uploads
  *
  * @access public
  * @param mixed &$Sender
  * @return void
  */
 public function PostController_Upload_Create($Sender)
 {
     if (!$this->IsEnabled()) {
         return;
     }
     list($FieldName) = $Sender->RequestArgs;
     $Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
     $Sender->DeliveryType(DELIVERY_TYPE_VIEW);
     $Sender->FieldName = $FieldName;
     $Sender->ApcKey = Gdn::Request()->GetValueFrom(Gdn_Request::INPUT_POST, 'APC_UPLOAD_PROGRESS');
     // this will hold the IDs and filenames of the items we were sent. booyahkashaa.
     $MediaResponse = array();
     $FileData = Gdn::Request()->GetValueFrom(Gdn_Request::INPUT_FILES, $FieldName, FALSE);
     try {
         if (!$this->CanUpload) {
             throw new FileUploadPluginUploadErrorException("You do not have permission to upload files", 11, '???');
         }
         if (!$Sender->Form->IsPostBack()) {
             $PostMaxSize = ini_get('post_max_size');
             throw new FileUploadPluginUploadErrorException("The post data was too big (max {$PostMaxSize})", 10, '???');
         }
         if (!$FileData) {
             //$PostMaxSize = ini_get('post_max_size');
             $MaxUploadSize = ini_get('upload_max_filesize');
             //throw new FileUploadPluginUploadErrorException("The uploaded file was too big (max {$MaxUploadSize})",10,'???');
             throw new FileUploadPluginUploadErrorException("No file data could be found in your post", 10, '???');
         }
         // Validate the file upload now.
         $FileErr = $FileData['error'];
         $FileType = $FileData['type'];
         $FileName = $FileData['name'];
         $FileTemp = $FileData['tmp_name'];
         $FileSize = $FileData['size'];
         $FileKey = $Sender->ApcKey ? $Sender->ApcKey : '';
         if ($FileErr != UPLOAD_ERR_OK) {
             $ErrorString = '';
             switch ($FileErr) {
                 case UPLOAD_ERR_INI_SIZE:
                     $MaxUploadSize = ini_get('upload_max_filesize');
                     $ErrorString = sprintf(T('The uploaded file was too big (max %s).'), $MaxUploadSize);
                     break;
                 case UPLOAD_ERR_FORM_SIZE:
                     $ErrorString = 'The uploaded file was too big';
                     break;
                 case UPLOAD_ERR_PARTIAL:
                     $ErrorString = 'The uploaded file was only partially uploaded';
                     break;
                 case UPLOAD_ERR_NO_FILE:
                     $ErrorString = 'No file was uploaded';
                     break;
                 case UPLOAD_ERR_NO_TMP_DIR:
                     $ErrorString = 'Missing a temporary folder';
                     break;
                 case UPLOAD_ERR_CANT_WRITE:
                     $ErrorString = 'Failed to write file to disk';
                     break;
                 case UPLOAD_ERR_EXTENSION:
                     $ErrorString = 'A PHP extension stopped the file upload';
                     break;
             }
             throw new FileUploadPluginUploadErrorException($ErrorString, $FileErr, $FileName, $FileKey);
         }
         $FileNameParts = pathinfo($FileName);
         $Extension = strtolower($FileNameParts['extension']);
         $AllowedExtensions = C('Garden.Upload.AllowedFileExtensions', array("*"));
         if (!in_array($Extension, $AllowedExtensions) && !in_array('*', $AllowedExtensions)) {
             throw new FileUploadPluginUploadErrorException("Uploaded file type is not allowed.", 11, $FileName, $FileKey);
         }
         $MaxUploadSize = Gdn_Upload::UnformatFileSize(C('Garden.Upload.MaxFileSize', '1G'));
         if ($FileSize > $MaxUploadSize) {
             $Message = sprintf(T('The uploaded file was too big (max %s).'), Gdn_Upload::FormatFileSize($MaxUploadSize));
             throw new FileUploadPluginUploadErrorException($Message, 11, $FileName, $FileKey);
         }
         $SaveFilename = md5(microtime()) . '.' . strtolower($Extension);
         $SaveFilename = '/FileUpload/' . substr($SaveFilename, 0, 2) . '/' . substr($SaveFilename, 2);
         $SavePath = MediaModel::PathUploads() . $SaveFilename;
         if (!is_dir(dirname($SavePath))) {
             @mkdir(dirname($SavePath), 0777, TRUE);
         }
         if (!is_dir(dirname($SavePath))) {
             throw new FileUploadPluginUploadErrorException("Internal error, could not save the file.", 9, $FileName);
         }
         $MoveSuccess = @move_uploaded_file($FileTemp, $SavePath);
         if (!$MoveSuccess) {
             throw new FileUploadPluginUploadErrorException("Internal error, could not move the file.", 9, $FileName);
         }
         // Get the image dimensions (if this is an image).
         list($ImageWidth, $ImageHeight) = MediaModel::GetImageSize($SavePath);
         $Media = array('Name' => $FileName, 'Type' => $FileType, 'Size' => $FileSize, 'ImageWidth' => $ImageWidth, 'ImageHeight' => $ImageHeight, 'InsertUserID' => Gdn::Session()->UserID, 'DateInserted' => date('Y-m-d H:i:s'), 'StorageMethod' => 'local', 'Path' => $SaveFilename);
         $MediaID = $this->MediaModel()->Save($Media);
         $FinalImageLocation = '';
//.........这里部分代码省略.........
开发者ID:ru4,项目名称:arabbnota,代码行数:101,代码来源:class.fileupload.plugin.php

示例3: PostController_Upload_Create

 /**
  * Allows plugin to handle ajax file uploads.
  *
  * @access public
  * @param object $Sender
  */
 public function PostController_Upload_Create($Sender)
 {
     if (!$this->IsEnabled()) {
         return;
     }
     list($FieldName) = $Sender->RequestArgs;
     $Sender->DeliveryMethod(DELIVERY_METHOD_JSON);
     $Sender->DeliveryType(DELIVERY_TYPE_VIEW);
     include_once $Sender->FetchViewLocation('fileupload_functions', '', 'plugins/FileUpload');
     $Sender->FieldName = $FieldName;
     $Sender->ApcKey = Gdn::Request()->GetValueFrom(Gdn_Request::INPUT_POST, 'APC_UPLOAD_PROGRESS');
     // this will hold the IDs and filenames of the items we were sent. booyahkashaa.
     $MediaResponse = array();
     $FileData = Gdn::Request()->GetValueFrom(Gdn_Request::INPUT_FILES, $FieldName, FALSE);
     try {
         if (!$this->CanUpload) {
             throw new FileUploadPluginUploadErrorException("You do not have permission to upload files", 11, '???');
         }
         if (!$Sender->Form->IsPostBack()) {
             $PostMaxSize = ini_get('post_max_size');
             throw new FileUploadPluginUploadErrorException("The post data was too big (max {$PostMaxSize})", 10, '???');
         }
         if (!$FileData) {
             //$PostMaxSize = ini_get('post_max_size');
             $MaxUploadSize = ini_get('upload_max_filesize');
             //throw new FileUploadPluginUploadErrorException("The uploaded file was too big (max {$MaxUploadSize})",10,'???');
             throw new FileUploadPluginUploadErrorException("No file data could be found in your post", 10, '???');
         }
         // Validate the file upload now.
         $FileErr = $FileData['error'];
         $FileType = $FileData['type'];
         $FileName = $FileData['name'];
         $FileTemp = $FileData['tmp_name'];
         $FileSize = $FileData['size'];
         $FileKey = $Sender->ApcKey ? $Sender->ApcKey : '';
         if ($FileErr != UPLOAD_ERR_OK) {
             $ErrorString = '';
             switch ($FileErr) {
                 case UPLOAD_ERR_INI_SIZE:
                     $MaxUploadSize = ini_get('upload_max_filesize');
                     $ErrorString = sprintf(T('The uploaded file was too big (max %s).'), $MaxUploadSize);
                     break;
                 case UPLOAD_ERR_FORM_SIZE:
                     $ErrorString = 'The uploaded file was too big';
                     break;
                 case UPLOAD_ERR_PARTIAL:
                     $ErrorString = 'The uploaded file was only partially uploaded';
                     break;
                 case UPLOAD_ERR_NO_FILE:
                     $ErrorString = 'No file was uploaded';
                     break;
                 case UPLOAD_ERR_NO_TMP_DIR:
                     $ErrorString = 'Missing a temporary folder';
                     break;
                 case UPLOAD_ERR_CANT_WRITE:
                     $ErrorString = 'Failed to write file to disk';
                     break;
                 case UPLOAD_ERR_EXTENSION:
                     $ErrorString = 'A PHP extension stopped the file upload';
                     break;
             }
             throw new FileUploadPluginUploadErrorException($ErrorString, $FileErr, $FileName, $FileKey);
         }
         // Analyze file extension
         $FileNameParts = pathinfo($FileName);
         $Extension = strtolower($FileNameParts['extension']);
         $AllowedExtensions = C('Garden.Upload.AllowedFileExtensions', array("*"));
         if (!in_array($Extension, $AllowedExtensions) && !in_array('*', $AllowedExtensions)) {
             throw new FileUploadPluginUploadErrorException("Uploaded file type is not allowed.", 11, $FileName, $FileKey);
         }
         // Check upload size
         $MaxUploadSize = Gdn_Upload::UnformatFileSize(C('Garden.Upload.MaxFileSize', '1G'));
         if ($FileSize > $MaxUploadSize) {
             $Message = sprintf(T('The uploaded file was too big (max %s).'), Gdn_Upload::FormatFileSize($MaxUploadSize));
             throw new FileUploadPluginUploadErrorException($Message, 11, $FileName, $FileKey);
         }
         // Build filename
         $SaveFilename = md5(microtime()) . '.' . strtolower($Extension);
         $SaveFilename = '/FileUpload/' . substr($SaveFilename, 0, 2) . '/' . substr($SaveFilename, 2);
         // Get the image size before doing anything.
         list($ImageWidth, $ImageHeight, $ImageType) = Gdn_UploadImage::ImageSize($FileTemp, $FileName);
         // Fire event for hooking save location
         $this->EventArguments['Path'] = $FileTemp;
         $Parsed = Gdn_Upload::Parse($SaveFilename);
         $this->EventArguments['Parsed'] =& $Parsed;
         $this->EventArguments['OriginalFilename'] = $FileName;
         $Handled = FALSE;
         $this->EventArguments['Handled'] =& $Handled;
         $this->EventArguments['ImageType'] = $ImageType;
         $this->FireAs('Gdn_Upload')->FireEvent('SaveAs');
         $SavePath = $Parsed['Name'];
         if (!$Handled) {
             // Build save location
             $SavePath = MediaModel::PathUploads() . $SaveFilename;
//.........这里部分代码省略.........
开发者ID:SatiricMan,项目名称:addons,代码行数:101,代码来源:class.fileupload.plugin.php

示例4: number_format

    ?>
</dd>

                    <dt>Downloads</dt>
                    <dd><meta itemprop="interactionCount" content="UserDownloads:<?php 
    echo $this->data('CountDownloads');
    ?>
" /><?php 
    echo number_format($this->data('CountDownloads'));
    ?>
</dd>

                    <?php 
    if ($this->data('FileSize')) {
        echo wrap(t('File Size'), 'dt');
        echo wrap('<meta itemprop="fileSize" content="' . $this->data('FileSize') . '"/>' . Gdn_Upload::FormatFileSize($this->data('FileSize')), 'dd');
    }
    if ($this->data('License')) {
        echo wrap(t('License'), 'dt');
        echo wrap(htmlspecialchars($this->data('License')), 'dd');
    }
    if ($this->data('GitHub')) {
        echo wrap(t('GitHub'), 'dt');
        $github = stringBeginsWith($this->data('GitHub'), 'https://github.com/', false, true);
        echo wrap(anchor(htmlspecialchars($github), 'https://github.com/' . $github), 'dd');
    }
    $this->fireEvent('AddonProperties');
    ?>
                </dl>
            </div>
开发者ID:vanilla,项目名称:community,代码行数:30,代码来源:addon.php


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