Exemplo n.º 1
0
 public function upload()
 {
     $this->file = UploadedFile::getInstance($this, 'file');
     if (!$this->validate()) {
         return false;
     }
     $tmp_name = sha1($this->file->baseName) . uniqid('', true);
     $this->file->saveAs(Yii::$app->params['uploadFolder'] . $tmp_name);
     $pdfs = new Pdfs();
     $pdfs->title = $this->title;
     $pdfs->description = $this->description;
     $pdfs->tmp_name = $tmp_name;
     $pdfs->file_name = $this->file->baseName . '.' . $this->file->extension;
     $pdfs->size = (int) ($this->file->size / 1024);
     return $pdfs->save();
 }
Exemplo n.º 2
0
 public function actionViewPdf($id)
 {
     if (Yii::$app->user->isGuest) {
         throw new \yii\web\ForbiddenHttpException('<div class="alert">Thank you for your interest in this content. You must be logged in as a registered user to view this page in its entirety.</div>');
     }
     if (!Yii::$app->user->can('show', Yii::$app->user->identity)) {
         throw new \yii\web\ForbiddenHttpException(Yii::t('app', '<div class="alert"><h4>Expired Account</h4>Thank you for your interest in this content, but your account is no longer current. Please <a href="renew.php">renew your account</a> in order to view this page in its entirety.</div>'));
     }
     $pdf = Pdfs::find()->where('tmp_name=:tmp_name', [':tmp_name' => $id])->one();
     if (empty($pdf)) {
         throw new \yii\web\NotFoundHttpException();
     }
     $file = Yii::$app->params['uploadFolder'] . $pdf->tmp_name;
     $web = Yii::getAlias('@webroot') . '/';
     $view = $web . $file;
     header('Content-type:application/pdf');
     header('Content-Disposition:inline;filename="' . $pdf->file_name . '"');
     $fs = filesize($view);
     header("Content-Length:{$fs}\n");
     // Send the file:
     readfile($view);
 }
Exemplo n.º 3
0
 public function init()
 {
     $this->categories = Categories::find()->orderBy('category')->all();
     $this->pdfs = Pdfs::find()->count();
 }