Answer the question
In order to leave comments, you need to log in
How to create a button that will download a file when clicked?
There is a small blog on Yii, I decided to make a button for downloading files. There is a public function in the Article.php file:
public function getFile()
{
$file = \Yii::getAlias('@app/files/' . $this->file);
if (file_exists($file)) {
\Yii::$app->response->sendFile($file);
}
}
<a href="<?= $article->getFile();?>" download></a>
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