예제 #1
0
 /**
  * @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);
 }
예제 #2
0
 /**
  * @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]);
 }
예제 #3
0
 /**
  * @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);
 }