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


PHP Gdn_UploadImage::GetUploadedFileExtension方法代码示例

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


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

示例1: SaveImage

 /**
  * Save an image from a field and delete any old image that's been uploaded.
  * 
  * @param string $Field The name of the field. The image will be uploaded with the _New extension while the current image will be just the field name.
  * @param array $Options
  */
 public function SaveImage($Field, $Options = array())
 {
     $Upload = new Gdn_UploadImage();
     $FileField = str_replace('.', '_', $Field);
     if (!GetValueR("{$FileField}_New.name", $_FILES)) {
         Trace("{$Field} not uploaded, returning.");
         return FALSE;
     }
     // First make sure the file is valid.
     try {
         $TmpName = $Upload->ValidateUpload($FileField . '_New', TRUE);
         if (!$TmpName) {
             return FALSE;
         }
         // no file uploaded.
     } catch (Exception $Ex) {
         $this->AddError($Ex);
         return FALSE;
     }
     // Get the file extension of the file.
     $Ext = GetValue('OutputType', $Options, trim($Upload->GetUploadedFileExtension(), '.'));
     if ($Ext == 'jpeg') {
         $Ext = 'jpg';
     }
     Trace($Ext, 'Ext');
     // The file is valid so let's come up with its new name.
     if (isset($Options['Name'])) {
         $Name = $Options['Name'];
     } elseif (isset($Options['Prefix'])) {
         $Name = $Options['Prefix'] . md5(microtime()) . '.' . $Ext;
     } else {
         $Name = md5(microtime()) . '.' . $Ext;
     }
     // We need to parse out the size.
     $Size = GetValue('Size', $Options);
     if ($Size) {
         if (is_numeric($Size)) {
             TouchValue('Width', $Options, $Size);
             TouchValue('Height', $Options, $Size);
         } elseif (preg_match('`(\\d+)x(\\d+)`i', $Size, $M)) {
             TouchValue('Width', $Options, $M[1]);
             TouchValue('Height', $Options, $M[2]);
         }
     }
     Trace($Options, "Saving image {$Name}.");
     try {
         $Parsed = $Upload->SaveImageAs($TmpName, $Name, GetValue('Height', $Options, ''), GetValue('Width', $Options, ''), $Options);
         Trace($Parsed, 'Saved Image');
         $Current = $this->GetFormValue($Field);
         if ($Current && GetValue('DeleteOriginal', $Options, TRUE)) {
             // Delete the current image.
             Trace("Deleting original image: {$Current}.");
             if ($Current) {
                 $Upload->Delete($Current);
             }
         }
         // Set the current value.
         $this->SetFormValue($Field, $Parsed['SaveName']);
     } catch (Exception $Ex) {
         $this->AddError($Ex);
     }
 }
开发者ID:elpum,项目名称:TgaForumBundle,代码行数:68,代码来源:class.form.php


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