public function getImageOriginal() { if (file_exists($this->pathForIcons . "/apple-icon-original.png")) { $this->imageOriginal = UploadedFile::getInstance($model, 'imageOriginal'); } return $this->imageOriginal; }
public function actionUpload() { $model = new UploadForm(); if (Yii::$app->request->isPost) { $tanggal = date("YmdHis"); $model->file = UploadedFile::getInstance($model, 'file'); if ($model->file && $model->validate()) { $model->file->saveAs('uploads/data_prospek/' . $model->file->baseName . $tanggal . '.' . $model->file->extension); //$this->actionExupload(); } } return $this->render('upload', ['model' => $model]); }
public function actionCreate() { $model = new MeForm(); if ($model->load(Yii::$app->request->post())) { $model->file = UploadedFile::getInstance($model, 'file'); $photoName = 'uploads/' . $model->title . '.' . $model->file->extension; $model->file->saveAs($photoName); $model->photo = $photoName; $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('create', ['model' => $model]); } }
/** * @inheritdoc */ public function run() { $model = $this->model; if ($model->load($_POST)) { $file = UploadedFile::getInstance($model, 'file'); $model->fileName = $file->getBaseName() . '.' . $file->getExtension(); if ($model->validate()) { $uploaded = $file->saveAs(Yii::getAlias('@app/web/imgs') . "/{$model->path}"); } else { print_r($model->getErrors()); } } Yii::$app->response->format = Response::FORMAT_JSON; return ['files' => [['url' => "/imgs/{$model->path}", 'name' => 'name', 'type' => 'type', 'size' => 18932, 'deleteUrl' => 'url', 'deleteType' => 'DELETE']]]; }
public function saveUploadedFile($model, $attribute, $fileName = null, $obj = false, $returnObj = false) { $result = UploadedFile::getInstance($model, $attribute); if ($fileName == null) { $fileName = time() . '.' . $result->getExtension(); } if (strpos($fileName, "/") !== false) { $fileSubPath = substr($fileName, 0, strrpos($fileName, "/")); if (!is_dir($this->basePath . '/' . $fileSubPath)) { mkdir($this->basePath . '/' . $fileSubPath, $this->filePermission, true); } } if ($result->saveAs($this->basePath . "/" . $fileName)) { chmod($this->basePath . "/" . $fileName, $this->filePermission); } return $returnObj ? $returnObj : $fileName; }
/** * Updates an existing News model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $form = new UploadForm(); if ($model->load(Yii::$app->request->post())) { if ($form->image = UploadedFile::getInstance($form, 'image')) { $model->pic = 'image/' . md5($_SERVER['REQUEST_TIME'] . $form->image->baseName) . $_SERVER['REQUEST_TIME'] . '.' . $form->image->extension; $form->image->saveAs($model->pic); } if ($model->type != 4) { $model->pic = ''; } $model->save(); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'uploadForm' => $form]); } }