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


PHP File::setFromValidatedFile方法代码示例

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


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

示例1: executeImage

 public function executeImage(sfWebRequest $request)
 {
     $member = $this->getRoute()->getMember();
     if (!$member) {
         return sfView::NONE;
     }
     $message = $request->getMailMessage();
     $images = $message->getImages();
     foreach ($images as $image) {
         $count = $member->getMemberImage()->count();
         if ($count >= 3) {
             return sfView::ERROR;
         }
         $validator = new opValidatorImageFile();
         $validFile = $validator->clean($image);
         $file = new File();
         $file->setFromValidatedFile($validFile);
         $file->setName('m_' . $member->getId() . '_' . $file->getName());
         $memberImage = new MemberImage();
         $memberImage->setMember($member);
         $memberImage->setFile($file);
         if (!$count) {
             $memberImage->setIsPrimary(true);
         }
         $memberImage->save();
     }
     return sfView::NONE;
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:28,代码来源:actions.class.php

示例2: executePost

 public function executePost(sfWebRequest $request)
 {
     $this->forward400If('' === (string) $request['body'], 'body parameter is not specified.');
     $this->forward400If('' === (string) $request['toMember'], 'toMember parameter is not specified.');
     $body = $request['body'];
     $this->myMember = $this->member;
     $toMember = Doctrine::getTable('Member')->find($request['toMember']);
     $this->forward400Unless($toMember, 'invalid member');
     $relation = Doctrine_Core::getTable('MemberRelationship')->retrieveByFromAndTo($toMember->getId(), $this->member->getId());
     $this->forward400If($relation && $relation->getIsAccessBlock(), 'Cannot send the message.');
     $message = Doctrine::getTable('SendMessageData')->sendMessage($toMember, SendMessageData::SMARTPHONE_SUBJECT, $body, array());
     $file = $request->getFiles('message_image');
     try {
         $validator = new opValidatorImageFile(array('required' => false));
         $clean = $validator->clean($file);
         if (is_null($clean)) {
             // if empty.
             return sfView::SUCCESS;
         }
     } catch (Exception $e) {
         $this->logMessage($e->getMessage());
         $this->forward400('This image file is invalid.');
     }
     $file = new File();
     $file->setFromValidatedFile($clean);
     $file->save();
     $messageFile = new MessageFile();
     $messageFile->setMessageId($message->getId());
     $messageFile->setFile($file);
     $messageFile->save();
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:31,代码来源:actions.class.php

示例3: executeImage

 public function executeImage(sfWebRequest $request)
 {
     $member = $this->getRoute()->getMember();
     if (!$member) {
         return sfView::NONE;
     }
     $community = Doctrine::getTable('Community')->find($request->getParameter('id'));
     if (!$community) {
         return sfView::ERROR;
     }
     $isAdmin = Doctrine::getTable('CommunityMember')->isAdmin($member->getId(), $community->getId());
     if (!$isAdmin || $community->getImageFileName()) {
         return sfView::ERROR;
     }
     $message = $request->getMailMessage();
     if ($images = $message->getImages()) {
         $image = array_shift($images);
         $validator = new opValidatorImageFile();
         $validFile = $validator->clean($image);
         $file = new File();
         $file->setFromValidatedFile($validFile);
         $file->setName('c_' . $community->getId() . '_' . $file->getName());
         $community->setFile($file);
         $community->save();
     }
     return sfView::NONE;
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:27,代码来源:actions.class.php

示例4: save

 public function save()
 {
     $file = new File();
     $file->setFromValidatedFile($this->getValue('file'));
     $file->setName(sprintf('admin_%s_%d', $this->getValue('imageName'), time()));
     return $file->save();
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:7,代码来源:ImageForm.php

示例5: doSave

 protected function doSave($conn = null)
 {
     $file = new File();
     $file->setFromValidatedFile($this->getValue('file_id'));
     $file->name = 'op_mtviewer_' . $this->getObject()->id . '_' . $file->name;
     $this->getObject()->File = $file;
     parent::doSave($conn);
 }
开发者ID:upsilon,项目名称:opMTViewerPlugin,代码行数:8,代码来源:PluginImportJobForm.class.php

示例6: updateObject

 public function updateObject($values = null)
 {
     if ($values['photo'] instanceof sfValidatedFile) {
         $file = new File();
         $file->setFromValidatedFile($values['photo']);
         $this->getObject()->setFile($file);
     } else {
         $this->getObject()->setFile(null);
     }
 }
开发者ID:meruto,项目名称:opDiaryPlugin,代码行数:10,代码来源:PluginDiaryCommentImageForm.class.php

示例7: executePost

 public function executePost(sfWebRequest $request)
 {
     $this->forward400If('' === (string) $request['title'], 'title parameter is not specified.');
     $this->forward400If('' === (string) $request['body'], 'body parameter is not specified.');
     $this->forward400If(!isset($request['public_flag']) || '' === (string) $request['public_flag'], 'public flag is not specified');
     if (isset($request['id']) && '' !== $request['id']) {
         $diary = Doctrine::getTable('Diary')->findOneById($request['id']);
         $this->forward400If(false === $diary, 'the specified diary does not exit.');
         $this->forward400If(false === $diary->isAuthor($this->member->getId()), 'this diary is not yours.');
     } else {
         $diary = new Diary();
         $diary->setMemberId($this->member->getId());
     }
     $diary->setTitle($request['title']);
     $diary->setBody($request['body']);
     $diary->setPublicFlag($request['public_flag']);
     $diary->save();
     $this->diary = $diary;
     for ($i = 1; $i <= 3; $i++) {
         $diaryImage = Doctrine::getTable('DiaryImage')->retrieveByDiaryIdAndNumber($diary->getId(), $i);
         $filename = basename($_FILES['diary_photo_' . $i]['name']);
         if (!is_null($filename) && '' !== $filename) {
             try {
                 $validator = new opValidatorImageFile(array('required' => false));
                 $validFile = $validator->clean($_FILES['diary_photo_' . $i]);
             } catch (Exception $e) {
                 $this->forward400($e->getMessage());
             }
             $f = new File();
             $f->setFromValidatedFile($validFile);
             $f->setName(hash('md5', uniqid((string) $i) . $filename));
             if ($stream = fopen($_FILES['diary_photo_' . $i]['tmp_name'], 'r')) {
                 if (!is_null($diaryImage)) {
                     $diaryImage->delete();
                 }
                 $bin = new FileBin();
                 $bin->setBin(stream_get_contents($stream));
                 $f->setFileBin($bin);
                 $f->save();
                 $di = new DiaryImage();
                 $di->setDiaryId($diary->getId());
                 $di->setFileId($f->getId());
                 $di->setNumber($i);
                 $di->save();
                 $diary->updateHasImages();
             } else {
                 $this->forward400(__('Failed to write file to disk.'));
             }
         }
         $deleteCheck = $request['diary_photo_' . $i . '_photo_delete'];
         if ('on' === $deleteCheck && !is_null($diaryImage)) {
             $diaryImage->delete();
         }
     }
 }
开发者ID:meruto,项目名称:opDiaryPlugin,代码行数:55,代码来源:actions.class.php

示例8: save

 public function save()
 {
     $file = new File();
     $file->setFromValidatedFile($this->getValue('file'));
     $file->setName('b_' . $file->getName());
     if ($this->isNew()) {
         $bannerImage = new BannerImage();
     } else {
         $bannerImage = $this->getObject();
     }
     $bannerImage->setFile($file);
     $bannerImage->setUrl($this->getValue('url'));
     $bannerImage->setName($this->getValue('name'));
     return $bannerImage->save();
 }
开发者ID:phenom,项目名称:OpenPNE3,代码行数:15,代码来源:BannerImageForm.class.php

示例9: updateObject

 public function updateObject($values = null)
 {
     if ($values['photo'] instanceof sfValidatedFile) {
         if (!$this->isNew()) {
             unset($this->getObject()->File);
         }
         $file = new File();
         $file->setFromValidatedFile($values['photo']);
         $this->getObject()->setFile($file);
     } else {
         if (!$this->isNew() && !empty($values['photo_delete'])) {
             $this->getObject()->getFile()->delete();
         }
     }
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:15,代码来源:opCommunityTopicPluginImageForm.class.php

示例10: updateObject

 public function updateObject($values = null)
 {
     if ($values['image'] instanceof sfValidatedFile) {
         if (!$this->isNew()) {
             unset($this->getObject()->File);
         }
         $file = new File();
         $file->setFromValidatedFile($values['image']);
         $this->getObject()->setFile($file);
         return;
     }
     if (!empty($values['image_delete']) && !$this->isNew()) {
         $this->getObject()->getFile()->delete();
     }
     $this->object = null;
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:16,代码来源:PluginMessageFileForm.class.php

示例11: save

 public function save()
 {
     $target = $this->getOption('target');
     $rawConfig = Doctrine::getTable('SkinConfig')->retrieveByPluginAndName('opSkinClassicPlugin', $target . '_image');
     if ($rawConfig) {
         $file = Doctrine::getTable('File')->findOneByName($rawConfig->value);
         if ($file) {
             $file->delete();
         }
     }
     $file = new File();
     $file->setFromValidatedFile($this->getValue('image'));
     $file->save();
     opSkinClassicConfig::set($target . '_image', $file->name);
     opToolkit::clearCache();
 }
开发者ID:kawahara,项目名称:OpenPNE3,代码行数:16,代码来源:opSkinClassicImageForm.class.php

示例12: save

 public function save()
 {
     $count = $this->member->getMemberImage()->count();
     if ($count >= 3) {
         throw new opRuntimeException('Cannot add an image any more.');
     }
     $file = new File();
     $file->setFromValidatedFile($this->getValue('file'));
     $file->setName('m_' . $this->member->getId() . '_' . $file->getName());
     $memberImage = new MemberImage();
     $memberImage->setMember($this->member);
     $memberImage->setFile($file);
     if (!$count) {
         $memberImage->setIsPrimary(true);
     }
     return $memberImage->save();
 }
开发者ID:Kazuhiro-Murota,项目名称:OpenPNE3,代码行数:17,代码来源:MemberImageForm.class.php

示例13: getImageFiles

 protected function getImageFiles(opMailMessage $message, $num = null)
 {
     $files = array();
     $images = $message->getImages();
     $i = 1;
     foreach ($images as $image) {
         if (null !== $num && $i > $num) {
             break;
         }
         $validator = new opValidatorImageFile();
         $validFile = $validator->clean($image);
         $file = new File();
         $file->setFromValidatedFile($validFile);
         $files[] = $file;
         $i++;
     }
     return $files;
 }
开发者ID:meruto,项目名称:opDiaryPlugin,代码行数:18,代码来源:opDiaryPluginMailActions.class.php

示例14: save

 public function save()
 {
     if ($this->getValue('file')) {
         if ($this->community->getFile()) {
             $this->community->getFile()->delete();
         }
         $file = new File();
         $file->setFromValidatedFile($this->getValue('file'));
         $file->setName('c_' . $this->community->getId() . '_' . $file->getName());
         $this->community->setFile($file);
     } elseif ($this->getValue('file_delete')) {
         $this->community->getFile()->delete();
         $this->community->setFile(null);
     } else {
         return;
     }
     $this->community->save();
 }
开发者ID:te-koyama,项目名称:openpne,代码行数:18,代码来源:CommunityFileForm.class.php

示例15: updateObject

 public function updateObject($values = null)
 {
     if (is_null($values)) {
         $values = $this->values;
     }
     $photo = $values['photo'];
     unset($values['photo']);
     $object = parent::updateObject($values);
     if ($photo) {
         $file = new File();
         $file->setFromValidatedFile($photo);
         $old = $this->getObject()->getFile();
         $this->getObject()->setFile($file);
         $this->getObject()->save();
         $old->delete();
     }
     return $object;
 }
开发者ID:balibali,项目名称:opAlbumPlugin,代码行数:18,代码来源:PluginAlbumImageForm.class.php


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