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


PHP Gdn_UploadImage::GenerateTargetName方法代码示例

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


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

示例1: PostController_Imageupload_create

 public function PostController_Imageupload_create()
 {
     try {
         $UploadImage = new Gdn_UploadImage();
         $TmpImage = $UploadImage->ValidateUpload('image_file');
         // Generate the target image name.
         $TargetImage = $UploadImage->GenerateTargetName(PATH_UPLOADS . '/imageupload', '', TRUE);
         $Props = $UploadImage->SaveImageAs($TmpImage, $TargetImage, C('Plugins.UploadImage.MaxHeight', ''), C('Plugins.UploadImage.MaxWidth', 650));
         echo json_encode(array('url' => $Props['Url'], 'name' => $UploadImage->GetUploadedFileName()));
     } catch (Exception $e) {
         header('HTTP/1.0 400', TRUE, 400);
         echo $e;
     }
 }
开发者ID:edward-tsai,项目名称:vanilla4china,代码行数:14,代码来源:default.php

示例2: Picture

 public function Picture($UserReference = '', $Username = '')
 {
     $this->Permission('Garden.SignIn.Allow');
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         $this->Form->AddError('You must be authenticated in order to use this form.');
     }
     $ImageManipOk = FALSE;
     if (function_exists('gd_info')) {
         $GdInfo = gd_info();
         $GdVersion = preg_replace('/[a-z ()]+/i', '', $GdInfo['GD Version']);
         if ($GdVersion < 2) {
             throw new Exception(sprintf(T("This installation of GD is too old (v%s). Vanilla requires at least version 2 or compatible."), $GdVersion));
         }
     } else {
         throw new Exception(sprintf(T("Unable to detect PHP GD installed on this system. Vanilla requires GD version 2 or better.")));
     }
     $this->GetUserInfo($UserReference, $Username);
     $this->Form->SetModel($this->UserModel);
     $this->Form->AddHidden('UserID', $this->User->UserID);
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         $UploadImage = new Gdn_UploadImage();
         try {
             // Validate the upload
             $TmpImage = $UploadImage->ValidateUpload('Picture');
             // Generate the target image name
             $TargetImage = $UploadImage->GenerateTargetName(PATH_ROOT . DS . 'uploads');
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Delete any previously uploaded images
             @unlink(PATH_ROOT . '/uploads/' . ChangeBasename($this->User->Photo, 'p%s'));
             // Don't delete this one because it hangs around in activity streams:
             // @unlink(PATH_ROOT.'/uploads/'.ChangeBasename($this->User->Photo, 't%s'));
             @unlink(PATH_ROOT . '/uploads/' . ChangeBasename($this->User->Photo, 'n%s'));
             // Make sure the avatars folder exists.
             if (!file_exists(PATH_ROOT . '/uploads/userpics')) {
                 mkdir(PATH_ROOT . '/uploads/userpics');
             }
             // Save the uploaded image in profile size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . '/uploads/userpics/p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250));
             // Save the uploaded image in preview size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . '/uploads/userpics/t' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75));
             // Save the uploaded image in thumbnail size
             $ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50);
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . '/uploads/userpics/n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
         } catch (Exception $ex) {
             $this->Form->AddError($ex->getMessage());
         }
         // If there were no errors, associate the image with the user
         if ($this->Form->ErrorCount() == 0) {
             if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'Photo' => 'userpics/' . $ImageBaseName))) {
                 $this->Form->SetValidationResults($this->UserModel->ValidationResults());
             }
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->ErrorCount() == 0) {
             Redirect('dashboard/profile/' . $UserReference);
         }
     }
     if ($this->Form->ErrorCount() > 0) {
         $this->DeliveryType(DELIVERY_TYPE_ALL);
     }
     $this->Render();
 }
开发者ID:tautomers,项目名称:knoopvszombies,代码行数:63,代码来源:class.profilecontroller.php

示例3: Picture

 public function Picture($UserReference = '')
 {
     $this->Permission('Garden.SignIn.Allow');
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         $this->Form->AddError('You must be authenticated in order to use this form.');
     }
     $this->GetUserInfo($UserReference);
     $this->Form->SetModel($this->UserModel);
     $this->Form->AddHidden('UserID', $this->User->UserID);
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         $UploadImage = new Gdn_UploadImage();
         try {
             // Validate the upload
             $TmpImage = $UploadImage->ValidateUpload('Picture');
             // Generate the target image name
             $TargetImage = $UploadImage->GenerateTargetName(PATH_ROOT . DS . 'uploads');
             $ImageBaseName = pathinfo($TargetImage, PATHINFO_BASENAME);
             // Save the uploaded image in large size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'o' . $ImageBaseName, Gdn::Config('Garden.Picture.MaxHeight', 1000), Gdn::Config('Garden.Picture.MaxWidth', 1000));
             // Save the uploaded image in profile size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'p' . $ImageBaseName, Gdn::Config('Garden.Profile.MaxHeight', 1000), Gdn::Config('Garden.Profile.MaxWidth', 250));
             // Save the uploaded image in preview size
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 't' . $ImageBaseName, Gdn::Config('Garden.Preview.MaxHeight', 100), Gdn::Config('Garden.Preview.MaxWidth', 75));
             // Save the uploaded image in thumbnail size
             $ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50);
             $UploadImage->SaveImageAs($TmpImage, PATH_ROOT . DS . 'uploads' . DS . 'n' . $ImageBaseName, $ThumbSize, $ThumbSize, TRUE);
         } catch (Exception $ex) {
             $this->Form->AddError($ex->getMessage());
         }
         // If there were no errors, associate the image with the user
         if ($this->Form->ErrorCount() == 0) {
             $PhotoModel = new Model('Photo');
             $PhotoID = $PhotoModel->Insert(array('Name' => $ImageBaseName));
             if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'PhotoID' => $PhotoID, 'Photo' => $ImageBaseName))) {
                 $this->Form->SetValidationResults($this->UserModel->ValidationResults());
             }
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->ErrorCount() == 0) {
             Redirect('garden/profile/' . $UserReference);
         }
     }
     $this->Render();
 }
开发者ID:kidmax,项目名称:Garden,代码行数:45,代码来源:profile.php

示例4: Thumbnail

 /**
  * Set user's thumbnail (crop & center photo).
  *
  * @since 2.0.0
  * @access public
  * @param mixed $UserReference Unique identifier, possible username or ID.
  * @param string $Username.
  */
 public function Thumbnail($UserReference = '', $Username = '')
 {
     if (!C('Garden.Profile.EditPhotos', TRUE)) {
         throw ForbiddenException('@Editing user photos has been disabled.');
     }
     // Initial permission checks (valid user)
     $this->Permission('Garden.SignIn.Allow');
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         $this->Form->AddError('You must be authenticated in order to use this form.');
     }
     // Need some extra JS
     // jcrop update jan28, 2014 as jQuery upgrade to 1.10.2 no longer
     // supported browser()
     $this->AddJsFile('jquery.jcrop.min.js');
     $this->AddJsFile('profile.js');
     $this->GetUserInfo($UserReference, $Username, '', TRUE);
     // Permission check (correct user)
     if ($this->User->UserID != $Session->UserID && !CheckPermission('Garden.Users.Edit') && !CheckPermission('Moderation.Profiles.Edit')) {
         throw new Exception(T('You cannot edit the thumbnail of another member.'));
     }
     // Form prep
     $this->Form->SetModel($this->UserModel);
     $this->Form->AddHidden('UserID', $this->User->UserID);
     // Confirm we have a photo to manipulate
     if (!$this->User->Photo) {
         $this->Form->AddError('You must first upload a picture before you can create a thumbnail.');
     }
     // Define the thumbnail size
     $this->ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 40);
     // Define the source (profile sized) picture & dimensions.
     $Basename = ChangeBasename($this->User->Photo, 'p%s');
     $Upload = new Gdn_UploadImage();
     $PhotoParsed = Gdn_Upload::Parse($Basename);
     $Source = $Upload->CopyLocal($Basename);
     if (!$Source) {
         $this->Form->AddError('You cannot edit the thumbnail of an externally linked profile picture.');
     } else {
         $this->SourceSize = getimagesize($Source);
     }
     // We actually need to upload a new file to help with cdb ttls.
     $NewPhoto = $Upload->GenerateTargetName('userpics', trim(pathinfo($this->User->Photo, PATHINFO_EXTENSION), '.'), TRUE);
     // Add some more hidden form fields for jcrop
     $this->Form->AddHidden('x', '0');
     $this->Form->AddHidden('y', '0');
     $this->Form->AddHidden('w', $this->ThumbSize);
     $this->Form->AddHidden('h', $this->ThumbSize);
     $this->Form->AddHidden('HeightSource', $this->SourceSize[1]);
     $this->Form->AddHidden('WidthSource', $this->SourceSize[0]);
     $this->Form->AddHidden('ThumbSize', $this->ThumbSize);
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         try {
             // Get the dimensions from the form.
             Gdn_UploadImage::SaveImageAs($Source, ChangeBasename($NewPhoto, 'n%s'), $this->ThumbSize, $this->ThumbSize, array('Crop' => TRUE, 'SourceX' => $this->Form->GetValue('x'), 'SourceY' => $this->Form->GetValue('y'), 'SourceWidth' => $this->Form->GetValue('w'), 'SourceHeight' => $this->Form->GetValue('h')));
             // Save new profile picture.
             $Parsed = $Upload->SaveAs($Source, ChangeBasename($NewPhoto, 'p%s'));
             $UserPhoto = sprintf($Parsed['SaveFormat'], $NewPhoto);
             // Save the new photo info.
             Gdn::UserModel()->SetField($this->User->UserID, 'Photo', $UserPhoto);
             // Remove the old profile picture.
             @$Upload->Delete($Basename);
         } catch (Exception $Ex) {
             $this->Form->AddError($Ex);
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->ErrorCount() == 0) {
             Redirect(UserUrl($this->User, '', 'picture'));
             $this->InformMessage(Sprite('Check', 'InformSprite') . T('Your changes have been saved.'), 'Dismissable AutoDismiss HasSprite');
         }
     }
     // Delete the source image if it is externally hosted.
     if ($PhotoParsed['Type']) {
         @unlink($Source);
     }
     $this->Title(T('Edit My Thumbnail'));
     $this->_SetBreadcrumbs(T('Edit My Thumbnail'), '/profile/thumbnail');
     $this->Render();
 }
开发者ID:edward-tsai,项目名称:vanilla4china,代码行数:86,代码来源:class.profilecontroller.php

示例5: Picture

 /**
  * Set user's photo (avatar).
  *
  * @since 2.0.0
  * @access public
  * @param mixed $UserReference Unique identifier, possible username or ID.
  * @param string $Username.
  */
 public function Picture($UserReference = '', $Username = '', $UserID = '')
 {
     // Permission checks
     $this->Permission('Garden.Profiles.Edit');
     $Session = Gdn::Session();
     if (!$Session->IsValid()) {
         $this->Form->AddError('You must be authenticated in order to use this form.');
     }
     // Check ability to manipulate image
     $ImageManipOk = FALSE;
     if (function_exists('gd_info')) {
         $GdInfo = gd_info();
         $GdVersion = preg_replace('/[a-z ()]+/i', '', $GdInfo['GD Version']);
         if ($GdVersion < 2) {
             throw new Exception(sprintf(T("This installation of GD is too old (v%s). Vanilla requires at least version 2 or compatible."), $GdVersion));
         }
     } else {
         throw new Exception(sprintf(T("Unable to detect PHP GD installed on this system. Vanilla requires GD version 2 or better.")));
     }
     // Get user data & prep form.
     $this->GetUserInfo($UserReference, $Username, $UserID, TRUE);
     $this->Form->SetModel($this->UserModel);
     $this->Form->AddHidden('UserID', $this->User->UserID);
     if ($this->Form->AuthenticatedPostBack() === TRUE) {
         $UploadImage = new Gdn_UploadImage();
         try {
             // Validate the upload
             $TmpImage = $UploadImage->ValidateUpload('Picture');
             // Generate the target image name.
             $TargetImage = $UploadImage->GenerateTargetName(PATH_LOCAL_UPLOADS, '', TRUE);
             $Basename = pathinfo($TargetImage, PATHINFO_BASENAME);
             $Subdir = StringBeginsWith(dirname($TargetImage), PATH_LOCAL_UPLOADS . '/', FALSE, TRUE);
             // Delete any previously uploaded image.
             $UploadImage->Delete(ChangeBasename($this->User->Photo, 'p%s'));
             // Save the uploaded image in profile size.
             $Props = $UploadImage->SaveImageAs($TmpImage, "userpics/{$Subdir}/p{$Basename}", C('Garden.Profile.MaxHeight', 1000), C('Garden.Profile.MaxWidth', 250), array('SaveGif' => C('Garden.Thumbnail.SaveGif')));
             $UserPhoto = sprintf($Props['SaveFormat'], "userpics/{$Subdir}/{$Basename}");
             //            // Save the uploaded image in preview size
             //            $UploadImage->SaveImageAs(
             //               $TmpImage,
             //               'userpics/t'.$ImageBaseName,
             //               Gdn::Config('Garden.Preview.MaxHeight', 100),
             //               Gdn::Config('Garden.Preview.MaxWidth', 75)
             //            );
             // Save the uploaded image in thumbnail size
             $ThumbSize = Gdn::Config('Garden.Thumbnail.Size', 50);
             $UploadImage->SaveImageAs($TmpImage, "userpics/{$Subdir}/n{$Basename}", $ThumbSize, $ThumbSize, array('Crop' => TRUE, 'SaveGif' => C('Garden.Thumbnail.SaveGif')));
         } catch (Exception $Ex) {
             $this->Form->AddError($Ex);
         }
         // If there were no errors, associate the image with the user
         if ($this->Form->ErrorCount() == 0) {
             if (!$this->UserModel->Save(array('UserID' => $this->User->UserID, 'Photo' => $UserPhoto), array('CheckExisting' => TRUE))) {
                 $this->Form->SetValidationResults($this->UserModel->ValidationResults());
             }
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->ErrorCount() == 0) {
             Redirect('dashboard/profile/' . $this->ProfileUrl());
         }
     }
     if ($this->Form->ErrorCount() > 0) {
         $this->DeliveryType(DELIVERY_TYPE_ALL);
     }
     $this->Render();
 }
开发者ID:seedbank,项目名称:old-repo,代码行数:74,代码来源:class.profilecontroller.php

示例6: picture

 /**
  * Set user's photo (avatar).
  *
  * @since 2.0.0
  * @access public
  * @param mixed $UserReference Unique identifier, possible username or ID.
  * @param string $Username .
  */
 public function picture($UserReference = '', $Username = '', $UserID = '')
 {
     if (!Gdn::session()->checkRankedPermission(c('Garden.Profile.EditPhotos', true))) {
         throw forbiddenException('@Editing user photos has been disabled.');
     }
     // Permission checks
     $this->permission(array('Garden.Profiles.Edit', 'Moderation.Profiles.Edit', 'Garden.ProfilePicture.Edit'), false);
     $Session = Gdn::session();
     if (!$Session->isValid()) {
         $this->Form->addError('You must be authenticated in order to use this form.');
     }
     // Check ability to manipulate image
     $ImageManipOk = false;
     if (function_exists('gd_info')) {
         $GdInfo = gd_info();
         $GdVersion = preg_replace('/[a-z ()]+/i', '', $GdInfo['GD Version']);
         if ($GdVersion < 2) {
             throw new Exception(sprintf(t("This installation of GD is too old (v%s). Vanilla requires at least version 2 or compatible."), $GdVersion));
         }
     } else {
         throw new Exception(sprintf(t("Unable to detect PHP GD installed on this system. Vanilla requires GD version 2 or better.")));
     }
     // Get user data & prep form.
     if ($this->Form->authenticatedPostBack() && $this->Form->getFormValue('UserID')) {
         $UserID = $this->Form->getFormValue('UserID');
     }
     $this->getUserInfo($UserReference, $Username, $UserID, true);
     $this->Form->setModel($this->UserModel);
     if ($this->Form->authenticatedPostBack() === true) {
         $this->Form->setFormValue('UserID', $this->User->UserID);
         // Set user's Photo attribute to a URL, provided the current user has proper permission to do so.
         $photoUrl = $this->Form->getFormValue('Url', false);
         if ($photoUrl && Gdn::session()->checkPermission('Garden.Settings.Manage')) {
             if (isUrl($photoUrl) && filter_var($photoUrl, FILTER_VALIDATE_URL)) {
                 $UserPhoto = $photoUrl;
             } else {
                 $this->Form->addError('Invalid photo URL');
             }
         } else {
             $UploadImage = new Gdn_UploadImage();
             try {
                 // Validate the upload
                 $TmpImage = $UploadImage->ValidateUpload('Picture');
                 // Generate the target image name.
                 $TargetImage = $UploadImage->GenerateTargetName(PATH_UPLOADS, '', true);
                 $Basename = pathinfo($TargetImage, PATHINFO_BASENAME);
                 $Subdir = stringBeginsWith(dirname($TargetImage), PATH_UPLOADS . '/', false, true);
                 // Delete any previously uploaded image.
                 $UploadImage->delete(changeBasename($this->User->Photo, 'p%s'));
                 // Save the uploaded image in profile size.
                 $Props = $UploadImage->SaveImageAs($TmpImage, "userpics/{$Subdir}/p{$Basename}", c('Garden.Profile.MaxHeight', 1000), c('Garden.Profile.MaxWidth', 250), array('SaveGif' => c('Garden.Thumbnail.SaveGif')));
                 $UserPhoto = sprintf($Props['SaveFormat'], "userpics/{$Subdir}/{$Basename}");
                 //            // Save the uploaded image in preview size
                 //            $UploadImage->SaveImageAs(
                 //               $TmpImage,
                 //               'userpics/t'.$ImageBaseName,
                 //               Gdn::config('Garden.Preview.MaxHeight', 100),
                 //               Gdn::config('Garden.Preview.MaxWidth', 75)
                 //            );
                 // Save the uploaded image in thumbnail size
                 $ThumbSize = Gdn::config('Garden.Thumbnail.Size', 40);
                 $UploadImage->saveImageAs($TmpImage, "userpics/{$Subdir}/n{$Basename}", $ThumbSize, $ThumbSize, array('Crop' => true, 'SaveGif' => c('Garden.Thumbnail.SaveGif')));
             } catch (Exception $Ex) {
                 // Throw the exception on API calls.
                 if ($this->deliveryType() === DELIVERY_TYPE_DATA) {
                     throw $Ex;
                 }
                 $this->Form->addError($Ex);
             }
         }
         // If there were no errors, associate the image with the user
         if ($this->Form->errorCount() == 0) {
             if (!$this->UserModel->save(array('UserID' => $this->User->UserID, 'Photo' => $UserPhoto), array('CheckExisting' => true))) {
                 $this->Form->setValidationResults($this->UserModel->validationResults());
             } else {
                 $this->User->Photo = $UserPhoto;
                 setValue('Photo', $this->Data['Profile'], $UserPhoto);
                 setValue('PhotoUrl', $this->Data['Profile'], Gdn_Upload::url(changeBasename($UserPhoto, 'n%s')));
             }
         }
         // If there were no problems, redirect back to the user account
         if ($this->Form->errorCount() == 0 && $this->deliveryType() !== DELIVERY_TYPE_DATA) {
             $this->informMessage(sprite('Check', 'InformSprite') . t('Your changes have been saved.'), 'Dismissable AutoDismiss HasSprite');
             redirect($this->deliveryType() == DELIVERY_TYPE_VIEW ? userUrl($this->User) : userUrl($this->User, '', 'picture'));
         }
     }
     if ($this->Form->errorCount() > 0 && $this->deliveryType() !== DELIVERY_TYPE_DATA) {
         $this->deliveryType(DELIVERY_TYPE_ALL);
     }
     $this->title(t('Change Picture'));
     $this->_setBreadcrumbs(t('Change My Picture'), userUrl($this->User, '', 'picture'));
     $this->render();
//.........这里部分代码省略.........
开发者ID:korelstar,项目名称:vanilla,代码行数:101,代码来源:class.profilecontroller.php


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