php - Yii2: Where to store uploaded files? -
story:
user should upload private files server. , should have access files, read(like viewing images or pdf files). placed them not in web root, there no direct link them. after first request, when server publish them authenticated user, becomes available others web/assets/* links.
question:
is there way clear assets every request? or there better way publish private files owners?
you can request file php script (sorry, know yii1 syntax):
?r=resources/get&filename=filename.png public function actionget() { $filename = yii::app()->request->getparam('filename'); $filepath = __dir__.'/../../../files/'.$filename; $finfo = finfo_open(fileinfo_mime_type); $mime = finfo_file($finfo, $filename); if (file_exists($filepath) && yii::app()->user->canaccess($filename)) { header('content-type: '.$mime); header('content-disposition: inline; filename="'.$filename.'";'); readfile($file); } else { $this->redirect('site/index'); } }
Comments
Post a Comment