/** * @return string */ public function run() { $uploaded = UploadedFile::getInstanceByName($this->fileParam); $file = new File(); $file->fid = \Yii::$app->security->generateRandomString(16); $file->name = $uploaded->name; $file->extension = $uploaded->extension; $file->type = $uploaded->type; $file->save(); $uploaded->saveAs($file->path, true); return Json::encode($file->fid); }
/** * @return string */ public function run() { $this->registerClientScript(); $attributeValue = $this->model->{$this->attribute}; $file = File::findOne(['fid' => $attributeValue]); return $this->renderFile(dirname(__FILE__) . '/views/widget.php', ['id' => $this->options['id'], 'name' => Html::getInputName($this->model, $this->attribute), 'fileInputId' => $this->id, 'fileInputName' => "_fileinput_" . $this->id, 'fid' => $attributeValue, 'url' => isset($file) ? $file->url : null, 'uploadUrl' => $this->uploadUrl, 'deleteUrl' => $this->deleteUrl]); }
/** * @return string * @throws HttpException */ public function run() { $file = File::findOne(['fid' => $this->fileParam]); if (file_exists($file->path)) { unlink($file->path); } if ($file->delete() === FALSE) { throw new HttpException(400); } return Json::encode($this->fileParam); }