AppController.php
public function actionForce_to_download_file($id){ $transaction = Transaction::findOne($id); $file_path =Yii::getAlias("@UploadPath/yonfiles/").Yii::$app->user->identity->id."/"."images/"; $file_name = $transaction->image->name; header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: Binary"); header("Content-disposition: attachment; filename=".basename($file_path.$file_name)); echo readfile($file_path.$file_name); }
javascript
function force_download(fid){ var token = $("#token").val(); window.location.replace('https://programmerdesign.com/yonfile/transaction/force_to_download_file?id='+fid+'&access-token='+token) ; }