PHP Snippet 1:
public function actionDownload($filename = null) {
$file = $filename;
$this->updateMenuItems();
if (isset($file)) {
$sqlFile = $this->path . basename($file);
if (file_exists($sqlFile)) {
Yii::$app->response->sendFile($sqlFile);
}
//throw new HttpException(404, Yii::t('app', 'File not found'));
}
}
PHP Snippet 2:
public function actionDownload($file = null)
{
ini_set('max_execution_time', 0);
//ini_set('memory_limit', '512M');
$message = 'OK';
$this->layout = null;
$this->updateMenuItems();
$list = $this->getFileList();
$list = array_merge($list, $this->getFileList('*.zip'));
foreach ($list as $id => $filename) {
$columns = array();
$columns['id'] = $id;
$columns['name'] = basename($filename);
$columns['size'] = filesize($this->path . $filename);
$columns['create_time'] = date('Y-m-d H:i:s', filectime($this->path . $filename));
$columns['modified_time'] = date('Y-m-d H:i:s', filemtime($this->path . $filename));
if (date('M-d-Y' . ' \a\t ' . ' g:i A', filemtime($this->path . $filename)) > date('M-d-Y' . ' \a\t ' . ' g:i A', filectime($this->path . $filename))) {
$columns['modified_time'] = date('M-d-Y' . ' \a\t ' . ' g:i A', filemtime($this->path . $filename));
}
$dataArray[] = $columns;
}
$dataProvider = new ArrayDataProvider([
'allModels' => array_reverse($dataArray),
'sort' => [
'attributes' => [
'modified_time' => SORT_ASC
]
]
]);
if (isset($file)) {
// $sql = new MysqlBackup();
$sqlFile = $this->path . basename($file);
if (file_exists($sqlFile)) {
Yii::$app->response->sendFile($sqlFile);
}
}
return $this->render('restore', array(
'error' => $message,
'dataProvider' => $dataProvider
));
}