本文整理汇总了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;
}
示例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();
}
示例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;
}
示例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();
}
示例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);
}
示例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);
}
}
示例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();
}
}
}
示例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();
}
示例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();
}
}
}
示例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;
}
示例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();
}
示例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();
}
示例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;
}
示例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();
}
示例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;
}