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


PHP Gdn_Upload::ValidateUpload方法代码示例

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


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

示例1: Settings

 /**
  * Manage the current ranks and add new ones
  */
 public function Settings()
 {
     $this->Permission('Yaga.Ranks.Manage');
     $this->AddSideMenu('rank/settings');
     $this->Title(T('Yaga.Ranks.Manage'));
     // Get list of ranks from the model and pass to the view
     $this->SetData('Ranks', $this->RankModel->Get());
     if ($this->Form->IsPostBack() == TRUE) {
         // Handle the photo upload
         $Upload = new Gdn_Upload();
         $TmpImage = $Upload->ValidateUpload('PhotoUpload', FALSE);
         if ($TmpImage) {
             // Generate the target image name
             $TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS);
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Save the uploaded image
             $Parts = $Upload->SaveAs($TmpImage, 'yaga' . DS . $ImageBaseName);
             $RelativeUrl = StringBeginsWith($Parts['Url'], Gdn_Url::WebRoot(TRUE), TRUE, TRUE);
             SaveToConfig('Yaga.Ranks.Photo', $RelativeUrl);
             if (C('Yaga.Ranks.Photo') == $Parts['SaveName']) {
                 $this->InformMessage(T('Yaga.Rank.PhotoUploaded'));
             }
         }
     }
     include_once $this->FetchViewLocation('helper_functions', 'rank');
     $this->Render();
 }
开发者ID:hxii,项目名称:Application-Yaga,代码行数:30,代码来源:class.rankcontroller.php

示例2: ValidateUpload

 /**
  * Validates the uploaded image. Returns the temporary name of the uploaded file.
  */
 public function ValidateUpload($InputName)
 {
     // Make sure that all standard file upload checks are performed.
     $TmpFileName = parent::ValidateUpload($InputName);
     // Now perform image-specific checks
     $Size = getimagesize($TmpFileName);
     if ($Size === FALSE) {
         throw new Exception(Gdn::Translate('The uploaded file was not an image.'));
     }
     return $TmpFileName;
 }
开发者ID:Aetasiric,项目名称:Garden,代码行数:14,代码来源:class.uploadimage.php

示例3: ValidateUpload

 /**
  * Validates the uploaded image. Returns the temporary name of the uploaded file.
  */
 public function ValidateUpload($InputName)
 {
     if (!function_exists('gd_info')) {
         throw new Exception(T('The uploaded file could not be processed because GD is not installed.'));
     }
     // Make sure that all standard file upload checks are performed.
     $TmpFileName = parent::ValidateUpload($InputName);
     // Now perform image-specific checks
     $Size = getimagesize($TmpFileName);
     if ($Size === FALSE) {
         throw new Exception(T('The uploaded file was not an image.'));
     }
     return $TmpFileName;
 }
开发者ID:sheldon,项目名称:Garden,代码行数:17,代码来源:class.uploadimage.php

示例4: Import

 /**
  * Import a Yaga transport file
  */
 public function Import()
 {
     $this->Title(T('Yaga.Import'));
     $this->SetData('TransportType', 'Import');
     if (!class_exists('ZipArchive')) {
         $this->Form->AddError(T('Yaga.Error.TransportRequirements'));
     }
     if ($this->Form->IsPostBack() == TRUE) {
         // Handle the file upload
         $Upload = new Gdn_Upload();
         $TmpZip = $Upload->ValidateUpload('FileUpload', FALSE);
         $ZipFile = FALSE;
         if ($TmpZip) {
             // Generate the target name
             $TargetFile = $Upload->GenerateTargetName(PATH_UPLOADS, 'zip');
             $BaseName = pathinfo($TargetFile, PATHINFO_BASENAME);
             // Save the uploaded zip
             $Parts = $Upload->SaveAs($TmpZip, $BaseName);
             $ZipFile = PATH_UPLOADS . DS . $Parts['SaveName'];
             $this->SetData('TransportPath', $ZipFile);
         }
         $Include = $this->_FindIncludes();
         if (count($Include)) {
             $Info = $this->_ExtractZip($ZipFile);
             $this->_ImportData($Info, $Include);
             Gdn_FileSystem::RemoveFolder(PATH_UPLOADS . DS . 'import' . DS . 'yaga');
         } else {
             $this->Form->AddError(T('Yaga.Error.Includes'));
         }
     }
     if ($this->Form->ErrorCount() == 0 && $this->Form->IsPostBack()) {
         $this->Render('transport-success');
     } else {
         $this->Render();
     }
 }
开发者ID:hxii,项目名称:Application-Yaga,代码行数:39,代码来源:class.yagacontroller.php

示例5: index

 /**
  * Main import page.
  *
  * @since 2.0.0
  * @access public
  */
 public function index()
 {
     $this->permission('Garden.Import');
     // This permission doesn't exist, so only users with Admin == '1' will succeed.
     $Timer = new Gdn_Timer();
     // Determine the current step.
     $this->Form = new Gdn_Form();
     $Imp = new ImportModel();
     $Imp->loadState();
     // Search for the list of acceptable imports.
     $ImportPaths = array();
     $ExistingPaths = SafeGlob(PATH_UPLOADS . '/export*', array('gz', 'txt'));
     $ExistingPaths2 = SafeGlob(PATH_UPLOADS . '/porter/export*', array('gz'));
     $ExistingPaths = array_merge($ExistingPaths, $ExistingPaths2);
     foreach ($ExistingPaths as $Path) {
         $ImportPaths[$Path] = basename($Path);
     }
     // Add the database as a path.
     $ImportPaths = array_merge(array('db:' => t('This Database')), $ImportPaths);
     if ($Imp->CurrentStep < 1) {
         // Check to see if there is a file.
         $ImportPath = c('Garden.Import.ImportPath');
         $Validation = new Gdn_Validation();
         if (strcasecmp(Gdn::request()->requestMethod(), 'post') == 0) {
             $Upload = new Gdn_Upload();
             $Validation = new Gdn_Validation();
             if (count($ImportPaths) > 0) {
                 $Validation->applyRule('PathSelect', 'Required', t('You must select a file to import.'));
             }
             if (count($ImportPaths) == 0 || $this->Form->getFormValue('PathSelect') == 'NEW') {
                 $TmpFile = $Upload->ValidateUpload('ImportFile', false);
             } else {
                 $TmpFile = '';
             }
             if ($TmpFile) {
                 $Filename = $_FILES['ImportFile']['name'];
                 $Extension = pathinfo($Filename, PATHINFO_EXTENSION);
                 $TargetFolder = PATH_ROOT . DS . 'uploads' . DS . 'import';
                 if (!file_exists($TargetFolder)) {
                     mkdir($TargetFolder, 0777, true);
                 }
                 $ImportPath = $Upload->GenerateTargetName(PATH_ROOT . DS . 'uploads' . DS . 'import', $Extension);
                 $Upload->SaveAs($TmpFile, $ImportPath);
                 $Imp->ImportPath = $ImportPath;
                 $this->Form->setFormValue('PathSelect', $ImportPath);
                 $UploadedFiles = val('UploadedFiles', $Imp->Data);
                 $UploadedFiles[$ImportPath] = basename($Filename);
                 $Imp->Data['UploadedFiles'] = $UploadedFiles;
             } elseif ($PathSelect = $this->Form->getFormValue('PathSelect')) {
                 if ($PathSelect == 'NEW') {
                     $Validation->addValidationResult('ImportFile', 'ValidateRequired');
                 } else {
                     $Imp->ImportPath = $PathSelect;
                 }
             } elseif (!$Imp->ImportPath && count($ImportPaths) == 0) {
                 // There was no file uploaded this request or before.
                 $Validation->addValidationResult('ImportFile', $Upload->Exception);
             }
             // Validate the overwrite.
             if (true || strcasecmp($this->Form->getFormValue('Overwrite'), 'Overwrite') == 0) {
                 if (!stringBeginsWith($this->Form->getFormValue('PathSelect'), 'Db:', true)) {
                     $Validation->applyRule('Email', 'Required');
                 }
             }
             if ($Validation->validate($this->Form->formValues())) {
                 $this->Form->setFormValue('Overwrite', 'overwrite');
                 $Imp->fromPost($this->Form->formValues());
                 $this->View = 'Info';
             } else {
                 $this->Form->setValidationResults($Validation->results());
             }
         } else {
             $this->Form->setFormValue('PathSelect', $Imp->ImportPath);
         }
         $Imp->saveState();
     } else {
         $this->setData('Steps', $Imp->steps());
         $this->View = 'Info';
     }
     if (!stringBeginsWith($Imp->ImportPath, 'db:') && !file_exists($Imp->ImportPath)) {
         $Imp->deleteState();
     }
     try {
         $UploadedFiles = val('UploadedFiles', $Imp->Data, array());
         $ImportPaths = array_merge($ImportPaths, $UploadedFiles);
         $this->setData('ImportPaths', $ImportPaths);
         $this->setData('Header', $Imp->getImportHeader());
         $this->setData('Stats', val('Stats', $Imp->Data, array()));
         $this->setData('GenerateSQL', val('GenerateSQL', $Imp->Data));
         $this->setData('ImportPath', $Imp->ImportPath);
         $this->setData('OriginalFilename', val('OriginalFilename', $Imp->Data));
         $this->setData('CurrentStep', $Imp->CurrentStep);
         $this->setData('LoadSpeedWarning', $Imp->loadTableType(false) == 'LoadTableWithInsert');
     } catch (Gdn_UserException $Ex) {
//.........这里部分代码省略.........
开发者ID:mcnasby,项目名称:datto-vanilla,代码行数:101,代码来源:class.importcontroller.php

示例6: Banner

 /**
  * Banner management screen.
  */
 public function Banner()
 {
     $this->Permission('Garden.Settings.Manage');
     $this->AddSideMenu('dashboard/settings/banner');
     $this->Title(T('Banner'));
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->SetField(array('Garden.Title'));
     // Set the model on the form.
     $this->Form->SetModel($ConfigurationModel);
     // If seeing the form for the first time...
     if ($this->Form->AuthenticatedPostBack() === FALSE) {
         // Apply the config settings to the form.
         $this->Form->SetData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
         if ($this->Form->Save() !== FALSE) {
             $Upload = new Gdn_Upload();
             try {
                 // Validate the upload
                 $TmpImage = $Upload->ValidateUpload('Logo', FALSE);
                 if ($TmpImage) {
                     // Generate the target image name
                     $TargetImage = $Upload->GenerateTargetName(PATH_ROOT . DS . 'uploads');
                     $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
                     // Delete any previously uploaded images
                     @unlink(PATH_ROOT . DS . C('Garden.Logo', ''));
                     // Save the uploaded image
                     $Upload->SaveAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . $ImageBaseName);
                 }
             } catch (Exception $ex) {
                 $this->Form->AddError($ex->getMessage());
             }
             // If there were no errors, save the path to the logo in the config
             if ($this->Form->ErrorCount() == 0 && $Upload->GetUploadedFileName() != '') {
                 SaveToConfig('Garden.Logo', 'uploads' . DS . $ImageBaseName);
             }
             $this->StatusMessage = T("Your settings have been saved.");
         }
     }
     $this->Render();
 }
开发者ID:tautomers,项目名称:knoopvszombies,代码行数:46,代码来源:class.settingscontroller.php

示例7: Banner

 /**
  * Banner management screen.
  *
  * @since 2.0.0
  * @access public
  */
 public function Banner()
 {
     $this->Permission('Garden.Settings.Manage');
     $this->AddSideMenu('dashboard/settings/banner');
     $this->Title(T('Banner'));
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->SetField(array('Garden.HomepageTitle' => C('Garden.Title'), 'Garden.Title', 'Garden.Description'));
     // Set the model on the form.
     $this->Form->SetModel($ConfigurationModel);
     // Get the current logo.
     $Logo = C('Garden.Logo');
     if ($Logo) {
         $Logo = ltrim($Logo, '/');
         // Fix the logo path.
         if (StringBeginsWith($Logo, 'uploads/')) {
             $Logo = substr($Logo, strlen('uploads/'));
         }
         $this->SetData('Logo', $Logo);
     }
     // Get the current favicon.
     $Favicon = C('Garden.FavIcon');
     $this->SetData('Favicon', $Favicon);
     $ShareImage = C('Garden.ShareImage');
     $this->SetData('ShareImage', $ShareImage);
     // If seeing the form for the first time...
     if (!$this->Form->AuthenticatedPostBack()) {
         // Apply the config settings to the form.
         $this->Form->SetData($ConfigurationModel->Data);
     } else {
         // Define some validation rules for the fields being saved
         $ConfigurationModel->Validation->ApplyRule('Garden.Title', 'Required');
         $SaveData = array();
         if ($this->Form->Save() !== FALSE) {
             $Upload = new Gdn_Upload();
             try {
                 // Validate the upload
                 $TmpImage = $Upload->ValidateUpload('Logo', FALSE);
                 if ($TmpImage) {
                     // Generate the target image name
                     $TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS);
                     $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
                     // Delete any previously uploaded images.
                     if ($Logo) {
                         $Upload->Delete($Logo);
                     }
                     // Save the uploaded image
                     $Parts = $Upload->SaveAs($TmpImage, $ImageBaseName);
                     $ImageBaseName = $Parts['SaveName'];
                     $SaveData['Garden.Logo'] = $ImageBaseName;
                     $this->SetData('Logo', $ImageBaseName);
                 }
                 $ImgUpload = new Gdn_UploadImage();
                 $TmpFavicon = $ImgUpload->ValidateUpload('Favicon', FALSE);
                 if ($TmpFavicon) {
                     $ICOName = 'favicon_' . substr(md5(microtime()), 16) . '.ico';
                     if ($Favicon) {
                         $Upload->Delete($Favicon);
                     }
                     // Resize the to a png.
                     $Parts = $ImgUpload->SaveImageAs($TmpFavicon, $ICOName, 16, 16, array('OutputType' => 'ico', 'Crop' => TRUE));
                     $SaveData['Garden.FavIcon'] = $Parts['SaveName'];
                     $this->SetData('Favicon', $Parts['SaveName']);
                 }
                 $TmpShareImage = $Upload->ValidateUpload('ShareImage', FALSE);
                 if ($TmpShareImage) {
                     $TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS, FALSE);
                     $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
                     if ($ShareImage) {
                         $Upload->Delete($ShareImage);
                     }
                     $Parts = $Upload->SaveAs($TmpShareImage, $ImageBaseName);
                     $SaveData['Garden.ShareImage'] = $Parts['SaveName'];
                     $this->SetData('ShareImage', $Parts['SaveName']);
                 }
             } catch (Exception $ex) {
                 $this->Form->AddError($ex);
             }
             // If there were no errors, save the path to the logo in the config
             if ($this->Form->ErrorCount() == 0) {
                 SaveToConfig($SaveData);
             }
             $this->InformMessage(T("Your settings have been saved."));
         }
     }
     $this->Render();
 }
开发者ID:elpum,项目名称:TgaForumBundle,代码行数:93,代码来源:class.settingscontroller.php

示例8: Index

 public function Index()
 {
     $this->Permission('Garden.Import');
     // This permission doesn't exist, so only users with Admin == '1' will succeed.
     $Timer = new Gdn_Timer();
     // Determine the current step.
     $this->Form = new Gdn_Form();
     $Imp = new ImportModel();
     $Imp->LoadState();
     if ($Imp->CurrentStep < 1) {
         // Check to see if there is a file.
         $ImportPath = Gdn::Config('Garden.Import.ImportPath');
         $Validation = new Gdn_Validation();
         if (strcasecmp(Gdn::Request()->RequestMethod(), 'post') == 0) {
             $Upload = new Gdn_Upload();
             $Validation = new Gdn_Validation();
             $TmpFile = $Upload->ValidateUpload('ImportFile', FALSE);
             if ($TmpFile) {
                 $Filename = $_FILES['ImportFile']['name'];
                 $Extension = pathinfo($Filename, PATHINFO_EXTENSION);
                 $TargetFolder = PATH_ROOT . DS . 'uploads' . DS . 'import';
                 if (!file_exists($TargetFolder)) {
                     mkdir($TargetFolder, 0777, TRUE);
                 }
                 $ImportPath = $Upload->GenerateTargetName(PATH_ROOT . DS . 'uploads' . DS . 'import', $Extension);
                 $Upload->SaveAs($TmpFile, $ImportPath);
                 $Imp->ImportPath = $ImportPath;
                 $Imp->Data['OriginalFilename'] = basename($Filename);
             } elseif (!$Imp->ImportPath) {
                 // There was no file uploaded this request or before.
                 $Validation->AddValidationResult('ImportFile', $Upload->Exception);
             }
             // Validate the overwrite.
             if (strcasecmp($this->Form->GetFormValue('Overwrite'), 'Overwrite') == 0) {
                 $Validation->ApplyRule('Email', 'Required');
                 $Validation->ApplyRule('Password', 'Required');
             }
             if ($Validation->Validate($this->Form->FormValues())) {
                 $Imp->Overwrite($this->Form->GetFormValue('Overwrite', 'Overwrite'), $this->Form->GetFormValue('Email'), $this->Form->GetFormValue('Password'));
                 $this->View = 'Info';
             } else {
                 $this->Form->SetValidationResults($Validation->Results());
             }
         } else {
             // Search for an existing file that was uploaded by the web admin.
             $ImportPaths = SafeGlob(PATH_ROOT . DS . 'uploads' . DS . 'import' . DS . 'import.*');
             if ($ImportPaths) {
                 $ImportPath = $ImportPaths[0];
                 if (in_array(pathinfo($ImportPath, PATHINFO_EXTENSION), array('gz', 'txt'))) {
                     $Imp->ImportPath = $ImportPath;
                     $Imp->Data['OriginalFilename'] = basename($ImportPath);
                 }
             }
         }
         $Imp->SaveState();
     } else {
         $this->View = 'Info';
     }
     $this->SetData('Header', $Imp->GetImportHeader());
     $this->SetData('ImportPath', $Imp->ImportPath);
     $this->SetData('OriginalFilename', GetValue('OriginalFilename', $Imp->Data));
     $this->Render();
 }
开发者ID:sheldon,项目名称:Garden,代码行数:63,代码来源:class.importcontroller.php

示例9: EditCategory

 /**
  * Editing a category.
  *
  * @since 2.0.0
  * @access public
  *
  * @param int $CategoryID Unique ID of the category to be updated.
  */
 public function EditCategory($CategoryID = '')
 {
     // Check permission
     $this->Permission('Garden.Settings.Manage');
     // Set up models
     $RoleModel = new RoleModel();
     $PermissionModel = Gdn::PermissionModel();
     $this->Form->SetModel($this->CategoryModel);
     if (!$CategoryID && $this->Form->IsPostBack()) {
         if ($ID = $this->Form->GetFormValue('CategoryID')) {
             $CategoryID = $ID;
         }
     }
     // Get category data
     $this->Category = $this->CategoryModel->GetID($CategoryID);
     $this->Category->CustomPermissions = $this->Category->CategoryID == $this->Category->PermissionCategoryID;
     // Set up head
     $this->AddJsFile('jquery.alphanumeric.js');
     $this->AddJsFile('categories.js');
     $this->AddJsFile('jquery.gardencheckboxgrid.js');
     $this->Title(T('Edit Category'));
     $this->AddSideMenu('vanilla/settings/managecategories');
     // Make sure the form knows which item we are editing.
     $this->Form->AddHidden('CategoryID', $CategoryID);
     $this->SetData('CategoryID', $CategoryID);
     // Load all roles with editable permissions
     $this->RoleArray = $RoleModel->GetArray();
     $this->FireEvent('AddEditCategory');
     if ($this->Form->IsPostBack() == FALSE) {
         $this->Form->SetData($this->Category);
         $this->SetupDiscussionTypes($this->Category);
         $this->Form->SetValue('CustomPoints', $this->Category->PointsCategoryID == $this->Category->CategoryID);
     } else {
         $this->SetupDiscussionTypes($this->Category);
         $Upload = new Gdn_Upload();
         $TmpImage = $Upload->ValidateUpload('PhotoUpload', FALSE);
         if ($TmpImage) {
             // Generate the target image name
             $TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS);
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Save the uploaded image
             $Parts = $Upload->SaveAs($TmpImage, $ImageBaseName);
             $this->Form->SetFormValue('Photo', $Parts['SaveName']);
         }
         $this->Form->SetFormValue('CustomPoints', (bool) $this->Form->GetFormValue('CustomPoints'));
         if ($this->Form->Save()) {
             $Category = CategoryModel::Categories($CategoryID);
             $this->SetData('Category', $Category);
             if ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
                 Redirect('vanilla/settings/managecategories');
             }
         }
     }
     // Get all of the currently selected role/permission combinations for this junction.
     $Permissions = $PermissionModel->GetJunctionPermissions(array('JunctionID' => $CategoryID), 'Category', '', array('AddDefaults' => !$this->Category->CustomPermissions));
     $Permissions = $PermissionModel->UnpivotPermissions($Permissions, TRUE);
     if ($this->DeliveryType() == DELIVERY_TYPE_ALL) {
         $this->SetData('PermissionData', $Permissions, TRUE);
     }
     // Render default view
     $this->Render();
 }
开发者ID:edward-tsai,项目名称:vanilla4china,代码行数:70,代码来源:class.settingscontroller.php

示例10: Edit

 /**
  * Edit an existing badge or add a new one
  *
  * @param int $BadgeID
  * @throws ForbiddenException if no proper rules are found
  */
 public function Edit($BadgeID = NULL)
 {
     $this->Permission('Yaga.Badges.Manage');
     $this->AddSideMenu('badge/settings');
     $this->Form->SetModel($this->BadgeModel);
     // Only allow editing if some rules exist
     if (!RulesController::GetRules()) {
         throw new Gdn_UserException(T('Yaga.Error.NoRules'));
     }
     $Edit = FALSE;
     if ($BadgeID) {
         $this->Title(T('Yaga.Badge.Edit'));
         $this->Badge = $this->BadgeModel->GetByID($BadgeID);
         $this->Form->AddHidden('BadgeID', $BadgeID);
         $Edit = TRUE;
     } else {
         $this->Title(T('Yaga.Badge.Add'));
     }
     if ($this->Form->IsPostBack() == FALSE) {
         if (property_exists($this, 'Badge')) {
             // Manually merge the criteria into the badge object
             $Criteria = (array) unserialize($this->Badge->RuleCriteria);
             $BadgeArray = (array) $this->Badge;
             $Data = array_merge($BadgeArray, $Criteria);
             $this->Form->SetData($Data);
         }
     } else {
         // Handle the photo upload
         $Upload = new Gdn_Upload();
         $TmpImage = $Upload->ValidateUpload('PhotoUpload', FALSE);
         if ($TmpImage) {
             // Generate the target image name
             $TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS);
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Save the uploaded image
             $Parts = $Upload->SaveAs($TmpImage, 'yaga' . DS . $ImageBaseName);
             $RelativeUrl = StringBeginsWith($Parts['Url'], Gdn_Url::WebRoot(TRUE), TRUE, TRUE);
             $this->Form->SetFormValue('Photo', $RelativeUrl);
         } else {
             if (!$Edit) {
                 // Use default photo from config if this is a new badge
                 $this->Form->SetFormValue('Photo', C('Yaga.Badges.DefaultPhoto'));
             }
         }
         // Find the rule criteria
         $FormValues = $this->Form->FormValues();
         $Criteria = array();
         foreach ($FormValues as $Key => $Value) {
             if (substr($Key, 0, 7) == '_Rules/') {
                 $RealKey = substr($Key, 7);
                 $Criteria[$RealKey] = $Value;
             }
         }
         // Validate the criteria
         $RuleClass = new $FormValues['RuleClass']();
         $Rule = new $RuleClass();
         $Rule->Validate($Criteria, $this->Form);
         $SerializedCriteria = serialize($Criteria);
         $this->Form->SetFormValue('RuleCriteria', $SerializedCriteria);
         if ($this->Form->Save()) {
             if ($Edit) {
                 $this->InformMessage(T('Yaga.Badge.Updated'));
             } else {
                 $this->InformMessage(T('Yaga.Badge.Added'));
             }
             Redirect('/badge/settings');
         }
     }
     $this->Render('edit');
 }
开发者ID:hxii,项目名称:Application-Yaga,代码行数:76,代码来源:class.badgecontroller.php

示例11: banner

 /**
  * Banner management screen.
  *
  * @since 2.0.0
  * @access public
  */
 public function banner()
 {
     $this->permission(['Garden.Community.Manage', 'Garden.Settings.Manage'], false);
     $this->setHighlightRoute('dashboard/settings/banner');
     $this->title(t('Banner'));
     $Validation = new Gdn_Validation();
     $ConfigurationModel = new Gdn_ConfigurationModel($Validation);
     $ConfigurationModel->setField(array('Garden.HomepageTitle' => c('Garden.Title'), 'Garden.Title', 'Garden.Description'));
     // Set the model on the form.
     $this->Form->setModel($ConfigurationModel);
     // Get the current logo.
     $Logo = c('Garden.Logo');
     if ($Logo) {
         $Logo = ltrim($Logo, '/');
         // Fix the logo path.
         if (stringBeginsWith($Logo, 'uploads/')) {
             $Logo = substr($Logo, strlen('uploads/'));
         }
         $this->setData('Logo', $Logo);
     }
     // Get the current mobile logo.
     $MobileLogo = c('Garden.MobileLogo');
     if ($MobileLogo) {
         $MobileLogo = ltrim($MobileLogo, '/');
         // Fix the logo path.
         if (stringBeginsWith($MobileLogo, 'uploads/')) {
             $MobileLogo = substr($MobileLogo, strlen('uploads/'));
         }
         $this->setData('MobileLogo', $MobileLogo);
     }
     // Get the current favicon.
     $Favicon = c('Garden.FavIcon');
     $this->setData('Favicon', $Favicon);
     $ShareImage = c('Garden.ShareImage');
     $this->setData('ShareImage', $ShareImage);
     // If seeing the form for the first time...
     if (!$this->Form->authenticatedPostBack()) {
         // Apply the config settings to the form.
         $this->Form->setData($ConfigurationModel->Data);
     } else {
         $SaveData = array();
         if ($this->Form->save() !== false) {
             $Upload = new Gdn_Upload();
             try {
                 // Validate the upload
                 $TmpImage = $Upload->validateUpload('Logo', false);
                 if ($TmpImage) {
                     // Generate the target image name
                     $TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
                     $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
                     // Delete any previously uploaded images.
                     if ($Logo) {
                         $Upload->delete($Logo);
                     }
                     // Save the uploaded image
                     $Parts = $Upload->SaveAs($TmpImage, $ImageBaseName);
                     $ImageBaseName = $Parts['SaveName'];
                     $SaveData['Garden.Logo'] = $ImageBaseName;
                     $this->setData('Logo', $ImageBaseName);
                 }
                 $TmpMobileImage = $Upload->validateUpload('MobileLogo', false);
                 if ($TmpMobileImage) {
                     // Generate the target image name
                     $TargetImage = $Upload->generateTargetName(PATH_UPLOADS);
                     $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
                     // Delete any previously uploaded images.
                     if ($MobileLogo) {
                         $Upload->delete($MobileLogo);
                     }
                     // Save the uploaded image
                     $Parts = $Upload->saveAs($TmpMobileImage, $ImageBaseName);
                     $ImageBaseName = $Parts['SaveName'];
                     $SaveData['Garden.MobileLogo'] = $ImageBaseName;
                     $this->setData('MobileLogo', $ImageBaseName);
                 }
                 $ImgUpload = new Gdn_UploadImage();
                 $TmpFavicon = $ImgUpload->validateUpload('Favicon', false);
                 if ($TmpFavicon) {
                     $ICOName = 'favicon_' . substr(md5(microtime()), 16) . '.ico';
                     if ($Favicon) {
                         $Upload->delete($Favicon);
                     }
                     // Resize the to a png.
                     $Parts = $ImgUpload->SaveImageAs($TmpFavicon, $ICOName, 16, 16, array('OutputType' => 'ico', 'Crop' => true));
                     $SaveData['Garden.FavIcon'] = $Parts['SaveName'];
                     $this->setData('Favicon', $Parts['SaveName']);
                 }
                 $TmpShareImage = $Upload->ValidateUpload('ShareImage', false);
                 if ($TmpShareImage) {
                     $TargetImage = $Upload->GenerateTargetName(PATH_UPLOADS, false);
                     $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
                     if ($ShareImage) {
                         $Upload->delete($ShareImage);
                     }
//.........这里部分代码省略.........
开发者ID:vanilla,项目名称:vanilla,代码行数:101,代码来源:class.settingscontroller.php

示例12: UploadFile

 function UploadFile($TargetFolder, $InputName, $Options = False)
 {
     /*		if (is_array($InputName)) {
     			$Options = $InputName;
     			$InputName = $TargetFolder;
     		}*/
     $FileName = ArrayValue('name', ArrayValue($InputName, $_FILES));
     if ($FileName == '') {
         return;
     }
     // no upload, return null
     // options
     $AllowFileExtension = ArrayValue('AllowFileExtension', $Options);
     // TODO: $Overwrite is not used yet
     $CanOverwrite = ArrayValue('Overwrite', $Options, False);
     $CreateTargetFolder = ArrayValue('CreateTargetFolder', $Options, True);
     $WebTarget = ArrayValue('WebTarget', $Options);
     if ($CreateTargetFolder === True) {
         if (!file_exists($TargetFolder)) {
             mkdir($TargetFolder, 0777, True);
         }
         if (!is_writable($TargetFolder)) {
             throw new Exception(sprintf('Directory (%s) is not writable.', $TargetFolder));
         }
     }
     $Upload = new Gdn_Upload();
     if ($AllowFileExtension != False) {
         if (!is_array($AllowFileExtension)) {
             $AllowFileExtension = SplitString($AllowFileExtension);
         }
         foreach ($AllowFileExtension as $Extension) {
             $Upload->AllowFileExtension($Extension);
         }
     }
     $IsMultipleUpload = is_array($FileName);
     $Count = $IsMultipleUpload ? count($FileName) : 1;
     $OriginalFiles = $_FILES;
     $Result = array();
     for ($i = 0; $i < $Count; $i++) {
         if ($IsMultipleUpload != False) {
             $_FILES[$InputName] = array();
             foreach (array('name', 'type', 'tmp_name', 'error', 'size') as $Key) {
                 $Value = GetValueR($InputName . '.' . $Key . '.' . $i, $OriginalFiles);
                 SetValue($Key, $_FILES[$InputName], $Value);
             }
         } else {
             $FileName = array($FileName);
         }
         $TempFile = $Upload->ValidateUpload($InputName);
         $TargetFile = GenerateCleanTargetName($TargetFolder, $FileName[$i], '', $TempFile, $CanOverwrite);
         // 2.0.18 screwed Gdn_Upload::SaveAs()
         //$Upload->SaveAs($TempFile, $TargetFile);
         if (!move_uploaded_file($TempFile, $TargetFile)) {
             throw new Exception(sprintf(T('Failed to move uploaded file to target destination (%s).'), $TargetFile));
         }
         if ($WebTarget != False) {
             $File = str_replace(DS, '/', $TargetFile);
         } elseif (array_key_exists('WithTargetFolder', $Options)) {
             $File = $TargetFile;
         } else {
             $File = pathinfo($TargetFile, PATHINFO_BASENAME);
         }
         $Result[] = $File;
     }
     $_FILES = $OriginalFiles;
     if ($IsMultipleUpload) {
         return $Result;
     }
     return $File;
 }
开发者ID:ru4,项目名称:arabbnota,代码行数:70,代码来源:functions.file.php


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