Answer the question
In order to leave comments, you need to log in
How to properly create a virtual link in php?
Now I've done it like this:
public function actionFile($file){
$path = '';
if(Yii::$app->user->can('adminka')){
if($doc = Docs::find()->where(['file_name'=>$file])->one()){
$path = Yii::getAlias('@common').'/docs/'.$doc->user_id.'/'.$doc->file_name;
}
}else{
if($doc = Docs::find()->andWhere(['file_name'=>$file])->andWhere(['user_id'=>Yii::$app->user->id])->one()){
$path = Yii::getAlias('@common').'/docs/'.$doc->user_id.'/'.$doc->file_name;
}else{
throw new yii\web\ForbiddenHttpException;
}
}
if(!empty($path)){
$response = Yii::$app->response;
$response->format = \yii\web\Response::FORMAT_RAW;
$mime = yii\helpers\FileHelper::getMimeType($path);
header('Content-type: '.$mime);
echo file_get_contents($path);
}else{
throw new NotFoundHttpException;
}
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question