saveAs() public method

Note that this method uses php's move_uploaded_file() method. If the target file $file already exists, it will be overwritten.
See also: error
public saveAs ( string $file, boolean $deleteTempFile = true ) : boolean
$file string the file path used to save the uploaded file
$deleteTempFile boolean whether to delete the temporary file after saving. If true, you will not be able to save the uploaded file again in the current request.
return boolean true whether the file is saved successfully
コード例 #1
5
ファイル: Article.php プロジェクト: amarchenkov/myCMS
 public function afterSave($insert, $changedAttributes)
 {
     $this->preview_input = UploadedFile::getInstance($this, 'preview_input');
     if (!empty($this->preview_input)) {
         $this->preview_input->saveAs($this->preview_picture);
     }
     parent::afterSave($insert, $changedAttributes);
 }
コード例 #2
4
 public function upload()
 {
     if ($this->validate()) {
         $this->IMAGE->saveAs('upload/' . $this->IMAGE->baseName . '.' . $this->IMAGE->extension);
         return true;
     } else {
         return false;
     }
 }
コード例 #3
3
ファイル: Goods.php プロジェクト: RStuffGit/mebel
 public function uploadImage()
 {
     if ($this->validate() && $this->imageFile) {
         $this->imageFile->saveAs(Yii::getAlias("@webroot") . '/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
         return true;
     } else {
         return false;
     }
 }
コード例 #4
3
 public function upload()
 {
     if ($this->validate()) {
         $this->excelFile->saveAs(Yii::$app->basePath . '/uploads/' . $this->excelFile->baseName . '.' . $this->excelFile->extension);
         return true;
     } else {
         return false;
     }
 }
コード例 #5
2
ファイル: File.php プロジェクト: omnilight/yii2-models
 public function afterSave($insert, $changedAttributes)
 {
     if ($this->scenario == self::SCENARIO_FILE_UPLOAD) {
         $fileName = $this->getFileName();
         FileHelper::createDirectory(dirname($fileName));
         $this->fileUpload->saveAs($fileName);
     }
     parent::afterSave($insert, $changedAttributes);
 }
コード例 #6
2
ファイル: UploadForm.php プロジェクト: realphp/yii2-admin
 public function upload()
 {
     $uid = Yii::$app->user->getId();
     if ($this->validate()) {
         $path = 'uploads/excels/' . $uid . '_' . time() . '.' . $this->excelFile->extension;
         $this->excelFile->saveAs($path);
         return $path;
     } else {
         return false;
     }
 }
コード例 #7
1
ファイル: FileModel.php プロジェクト: kotmonstr/kotmonstr
 /**
  * @inherited
  */
 public function beforeSave($insert)
 {
     if ($this->file && $this->file instanceof UploadedFile && parent::beforeSave($insert)) {
         FileHelper::createDirectory(dirname($this->filename));
         return $this->file->saveAs($this->filename, false);
     }
     return false;
 }
コード例 #8
1
ファイル: UploadForm.php プロジェクト: bishabosha/flair
 public function upload()
 {
     if ($this->validate()) {
         $this->imageFile->saveAs('img/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
         return true;
     } else {
         return false;
     }
 }
コード例 #9
1
ファイル: UploadForm.php プロジェクト: eugenrein/koios
 public function upload()
 {
     if ($this->validate()) {
         $this->filename = \Yii::$app->security->generateRandomString() . '.' . $this->file->extension;
         $this->file->saveAs("uploads/{$this->filename}");
         return true;
     }
     return false;
 }
コード例 #10
1
ファイル: UploadForm.php プロジェクト: billcccheng/Yii2-Basic
 public function upload()
 {
     if ($this->validate()) {
         //yii::setAlias('@path1', 'localhost/basic/');
         $this->imageFile->saveAs(\Yii::$app->basePath . '/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
         return true;
     } else {
         return false;
     }
 }
コード例 #11
1
ファイル: UploadForm.php プロジェクト: havennow/sageone_test
 public function upload()
 {
     $file_path = \Yii::getAlias('@upload');
     if ($this->validate()) {
         $this->file->saveAs($file_path . $this->file->baseName . '.' . $this->file->extension);
         return true;
     } else {
         return false;
     }
 }
コード例 #12
1
ファイル: XmlUploadForm.php プロジェクト: jepster/yiipass
 public function upload()
 {
     // $this->getAttributes()
     $mime_type = \yii\helpers\FileHelper::getMimeType($this->file->tempName);
     if ($this->validate($mime_type)) {
         $this->file_path = 'uploads/' . $this->file->baseName . '.' . $this->file->extension;
         return $this->file->saveAs($this->file_path);
     } else {
         return false;
     }
 }
コード例 #13
1
ファイル: UploadForm.php プロジェクト: Denmal1982/zapomnit
 public function upload()
 {
     if ($this->validate()) {
         $this->imageHash = Yii::$app->security->generateRandomString(20) . '.' . $this->imageFile->extension;
         $path = 'uploads/' . $this->imageHash;
         $this->imageFile->saveAs($path);
         return true;
     } else {
         return false;
     }
 }
コード例 #14
1
ファイル: ConvectorForm.php プロジェクト: 7lion/testProject
 /**
  * @return null|string
  */
 public function upload()
 {
     if ($this->validate()) {
         $fileName = $this->imageFile->baseName . '.' . $this->imageFile->extension;
         $filePath = __DIR__ . '../../web/files/' . $fileName;
         $this->imageFile->saveAs($filePath);
         return $filePath;
     } else {
         return null;
     }
 }
コード例 #15
0
ファイル: FileUploadModel.php プロジェクト: apurey/cmf
 /**
  * @return bool
  */
 public function upload()
 {
     if ($this->validate()) {
         return $this->file->saveAs($this->getPath(), true);
     }
     return false;
 }
コード例 #16
0
ファイル: FileUploadModel.php プロジェクト: kintastish/mobil
 public function upload()
 {
     if ($this->validate()) {
         return $this->file->saveAs(Yii::$app->controller->module->getFilePath($this->getFileName()), true);
     }
     return false;
 }
コード例 #17
0
 /**
  * @param Book|null $book
  * @return boolean whether the book successfully edited
  */
 public function update($book)
 {
     if ($book) {
         if ($this->validate()) {
             $book->name = $this->name;
             $book->author_id = $this->author_id;
             $book->date = $this->date;
             if ($this->imageFile || $this->deleteImage) {
                 if (!empty($book->preview)) {
                     $imageToDelete = Yii::getAlias('@webroot') . Book::IMAGE_FOLDER . $book->preview;
                     if (file_exists($imageToDelete)) {
                         unlink($imageToDelete);
                     }
                     $book->preview = '';
                 }
             }
             if ($this->imageFile) {
                 $imageName = Yii::$app->security->generateRandomString() . '.' . $this->imageFile->extension;
                 if (!$this->imageFile->saveAs(Yii::getAlias('@webroot') . Book::IMAGE_FOLDER . $imageName)) {
                     return false;
                 }
                 $book->preview = $imageName;
             }
             return $book->save();
         }
     }
     return false;
 }
コード例 #18
0
ファイル: Books.php プロジェクト: Everus/rgk_test
 public function upload()
 {
     if ($this->imageFile = UploadedFile::getInstance($this, 'imageFile')) {
         $this->preview = md5($this->imageFile->baseName . time()) . '.' . $this->imageFile->extension;
         $this->imageFile->saveAs(Yii::getAlias('@webroot') . '/' . self::UPLOAD_DIR . $this->preview);
         $this->imageFile = NULL;
         Image::thumbnail('@webroot/' . self::UPLOAD_DIR . $this->preview, 120, 120)->save(Yii::getAlias('@webroot') . '/' . self::UPLOAD_DIR . 'thumb/' . $this->preview, ['quality' => 80]);
     }
 }
コード例 #19
0
 public function upload()
 {
     $done = $this->videoFile->saveAs('uploads/' . $this->videoFile->baseName . '.' . $this->videoFile->extension);
     if ($done) {
         return true;
     } else {
         return false;
     }
 }
コード例 #20
0
ファイル: ImageStorage.php プロジェクト: shurup312/autotape
 public function save()
 {
     $this->filename = $this->uploadedFile->baseName . '.' . $this->uploadedFile->extension;
     if ($this->uploadedFile->saveAs(Yii::getAlias('@webroot' . $this->uploadPath) . $this->filename)) {
         $this->model->filename = $this->filename;
         $this->model->path = $this->uploadPath;
         return true;
     }
     return false;
 }
コード例 #21
0
ファイル: VendorImage.php プロジェクト: black-lamp/blcms-shop
 public function Upload()
 {
     /** @var Imagable $image */
     $image = Yii::$app->shop_imagable;
     // save original
     $this->_orig_image_name = $this->imageFile->baseName . $this->_image_extension;
     $this->imageFile->saveAs($image->imagesPath . $this->_orig_image_name);
     // create small, thumb & big
     $this->_image_name = $image->create($this->_category, $image->imagesPath . $this->_orig_image_name);
     // delete original
     unlink($image->imagesPath . $this->_orig_image_name);
 }
コード例 #22
0
ファイル: News.php プロジェクト: Everus/idflyTest
 public function upload()
 {
     if ($this->validate()) {
         $this->image = 'uploads/news/' . $this->imageFile->baseName . '.' . $this->imageFile->extension;
         $this->imageFile->saveAs(Yii::getAlias('@webroot') . '/' . $this->image);
         $this->image = Yii::getAlias('@web') . '/' . $this->image;
         $this->imageFile = NULL;
         return true;
     } else {
         return false;
     }
 }
コード例 #23
0
ファイル: UploadForm.php プロジェクト: kennygp/yii-myweb
 public function upload($id)
 {
     if ($this->validate()) {
         $rootpath = 'upload/photo/' . $id . '/';
         $path = $rootpath . $this->photo->baseName . '.' . $this->photo->extension;
         @mkdir($rootpath, true);
         $this->photo->saveAs($path);
         return $path;
     } else {
         return false;
     }
 }
コード例 #24
0
ファイル: Categories.php プロジェクト: amarshimi/mini-market
 /**
  * @return bool
  */
 public function upload()
 {
     if ($this->validate()) {
         if (!file_exists('uploadImage')) {
             mkdir('uploadImage', 0777);
         }
         $this->imageFile->saveAs('uploadImage/' . $this->imageFile->baseName . '.' . $this->imageFile->extension);
         return true;
     } else {
         return false;
     }
 }
コード例 #25
0
ファイル: File.php プロジェクト: omnilight/yii2-files
 public function uploadFile(UploadedFile $fileUpload)
 {
     if ($this->name) {
         @unlink($this->getFileName());
     }
     $this->original_name = $fileUpload->name;
     $this->file_size = filesize($fileUpload->tempName);
     $this->name = $this->generateName();
     $this->updateAttributes(['original_name', 'name', 'file_size']);
     $fileName = $this->getFileName();
     FileHelper::createDirectory(dirname($fileName));
     $this->fileUpload->saveAs($fileName);
 }
コード例 #26
0
 /**
  * Upload file
  * @param File $model
  * @return bool
  */
 public function upload($model)
 {
     if ($this->validate()) {
         $model->name = FileHelper::removeExtension($this->file->name);
         $model->real_name = uniqid();
         $model->ext = $this->file->extension;
         $model->type = $this->file->type;
         $this->file->saveAs(FileHelper::getFilePath($model));
         return $model;
     } else {
         return false;
     }
 }
コード例 #27
0
ファイル: UploadFile1.php プロジェクト: kilinanatoly/zkam
 public function upload1($arenda_type_id)
 {
     if (!empty($this->imageFile)) {
         if ($this->validate()) {
             if (!file_exists("../web/images/arenda_types_images/" . $arenda_type_id)) {
                 mkdir("../web/images/arenda_types_images/" . $arenda_type_id, 0777);
             }
             $image_name = md5($this->imageFile->baseName) . date('His') . '.' . $this->imageFile->extension;
             $this->imageFile->saveAs('images/arenda_types_images/' . $arenda_type_id . '/' . $image_name);
             $model = ImagesForArendaTypes::findOne(['arenda_type_id' => $arenda_type_id]);
             if (!empty($model)) {
                 if (file_exists("../web/images/arenda_types_images/" . $arenda_type_id . '/' . $model->url)) {
                     unlink("../web/images/arenda_types_images/" . $arenda_type_id . '/' . $model->url);
                 }
             }
             if (empty($model)) {
                 $model = new ImagesForArendaTypes();
             }
             $model->url = $image_name;
             $model->arenda_type_id = $arenda_type_id;
             $model->save();
             return true;
         } else {
             return false;
         }
     }
     if (!empty($this->imageFile1)) {
         if ($this->validate()) {
             if (!file_exists("../web/images/arenda_types_images/" . $arenda_type_id)) {
                 mkdir("../web/images/arenda_types_images/" . $arenda_type_id, 0777);
             }
             $image_name = md5($this->imageFile1->baseName) . date('His') . '.' . $this->imageFile1->extension;
             $this->imageFile1->saveAs('images/arenda_types_images/' . $arenda_type_id . '/' . $image_name);
             $model = ImagesForArendaTypes::findOne(['arenda_type_id' => $arenda_type_id]);
             if (!empty($model)) {
                 if (file_exists("../web/images/arenda_types_images/" . $arenda_type_id . '/' . $model->url_black)) {
                     unlink("../web/images/arenda_types_images/" . $arenda_type_id . '/' . $model->url_black);
                 }
             }
             if (empty($model)) {
                 $model = new ImagesForArendaTypes();
             }
             $model->url_black = $image_name;
             $model->arenda_type_id = $arenda_type_id;
             $model->save();
             return true;
         } else {
             return false;
         }
     }
 }
コード例 #28
0
ファイル: PostCreateForm.php プロジェクト: ockor/yii2adv-blog
 public function upload()
 {
     if (!$this->hasErrors()) {
         $this->thumbnail = UploadedFile::getInstance($this, 'thumbnail');
         if ($this->thumbnail == null) {
             return false;
         }
         $this->thumbnail->saveAs('images/' . $this->thumbnail->baseName . '.' . $this->thumbnail->extension);
         $this->thumbnail = $this->thumbnail->baseName . '.' . $this->thumbnail->extension;
         return true;
     } else {
         return false;
     }
 }
コード例 #29
0
 public function upload()
 {
     if ($this->validate() && $this->imageFile) {
         $uploadDir = ArrayHelper::getValue(\Yii::$app->params, 'upload.common') . date('Ymd') . '/';
         if (!FileHelper::createDirectory($uploadDir)) {
             $this->addError('文件夹创建失败!请检查权限!', 'imageFile');
             return false;
         }
         $this->savePath = $uploadDir . \Yii::$app->getSecurity()->generateRandomString() . '.' . $this->imageFile->extension;
         return $this->imageFile->saveAs($this->savePath);
     } else {
         return false;
     }
 }
コード例 #30
-1
ファイル: UploadForm.php プロジェクト: soanni/stocks_mvc
 public function upload()
 {
     if ($this->validate()) {
         $this->csvFile->saveAs(Yii::getAlias('@uploads') . '/' . $this->csvFile->baseName . '.' . $this->csvFile->extension);
         return true;
     } else {
         return false;
     }
 }