コード例 #1
0
 public function userfilesAction()
 {
     $user = $this->session->getCurrentUser();
     if (is_null($this->request->getProperty('id'))) {
         throw new \Exception('Страница не найдена!');
     }
     $filesId = (int) $this->request->getProperty('id');
     $filesModel = new Files();
     $file = $filesModel->getUserFilesById($filesId, $user);
     $uploadDir = dirname(dirname(dirname(__DIR__))) . '/data/userfiles/';
     $uploadFile = $uploadDir . $file['id'];
     if (!file_exists($uploadFile)) {
         throw new \Exception('Файл не найден!');
     }
     $finfo = finfo_open(FILEINFO_MIME_TYPE);
     $mime = finfo_file($finfo, $uploadFile);
     header('Content-type: ' . $mime);
     header('Content-Description: File Transfer');
     header('Content-Disposition: attachment; filename="' . $file['filename'] . '"');
     header('Content-Transfer-Encoding: binary');
     header('Connection: Keep-Alive');
     header('Expires: 0');
     header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
     header('Pragma: public');
     header('Content-Length: ' . filesize($uploadFile));
     echo file_get_contents(urldecode($uploadFile));
     exit;
 }