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


PHP UploadedFile::saveAs方法代码示例

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


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

示例1: upload

 public function upload()
 {
     if ($this->validate()) {
         if (isset($this->avatarFile)) {
             if (!is_dir(Yii::$app->params['uploadPath'] . '/avatar')) {
                 mkdir(Yii::$app->params['uploadPath'] . '/avatar', 0777, true);
             }
             $this->avatarFile->saveAs(Yii::$app->params['uploadPath'] . '/avatar/' . $this->avatarFile->baseName . '.' . $this->avatarFile->extension);
             $this->avatar = '/avatar/' . $this->avatarFile->baseName . '.' . $this->avatarFile->extension;
             $this->save(false);
         }
         return true;
     } else {
         return false;
     }
 }
开发者ID:Mitonios,项目名称:mitonios-blog,代码行数:16,代码来源:Content.php

示例2: upload

 public function upload()
 {
     $this->setScenario('upload');
     if ($this->validate()) {
         $patch = Yii::getAlias('@uploads/' . $this->dirName);
         if (!is_dir($patch)) {
             mkdir($patch);
         }
         $fileName = 'sl_' . Yii::$app->security->generateRandomString(8) . '.' . $this->imageFile->extension;
         if ($this->imageFile->saveAs($patch . '/' . $fileName)) {
             $this->removeImage();
         }
         $this->image = $fileName;
         return true;
     }
     return false;
 }
开发者ID:mrbighokage,项目名称:book-test-yii2,代码行数:17,代码来源:Slide.php

示例3: saveUploadedFile

 /**
  * Save the uploaded file to filesystem path and optional resize before save it.
  */
 protected function saveUploadedFile()
 {
     $uniqueId = uniqid(mt_rand(100, 1000));
     $newName = $this->mediaFile->baseName . '_' . $uniqueId . '.' . $this->mediaFile->extension;
     $webroot = Yii::getAlias('@webroot');
     $dir = $webroot . DIRECTORY_SEPARATOR . $this->targetUrl;
     FileHelper::createDirectory($dir);
     $path = $dir . DIRECTORY_SEPARATOR . $newName;
     $this->name = $this->mediaFile->name;
     $this->url = $this->targetUrl . '/' . $newName;
     $this->type = $this->mediaFile->type;
     // resize the file (Check is done by [[addMediaRules]]
     if (is_array($this->resize)) {
         list($width, $height) = $this->resize;
         $image = \kmergen\media\helpers\Image::thumb($this->mediaFile->tempName, $width, $height)->save($path);
         $this->size = filesize($path);
     } else {
         $this->size = $this->mediaFile->size;
         $this->mediaFile->saveAs($path);
     }
 }
开发者ID:kmergen,项目名称:yii2-media,代码行数:24,代码来源:Media.php


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