We are moving our forum in GitHub Discussions. For questions about Phalcon v3/v4 you can visit here and for Phalcon v5 here.

Ajax phalcon php force file download

My download file path is in application/app/upfiles

    $request = new Phalcon\Http\Request();
    if ($request->isPost()) {
      if ($request->isAjax()) {
        $fileid = $this->request->getPost('downloadpdf'); //get upload id from ajax post
        $download = Upload::findFirst("upload_id = '$fileid'");
        $filename = $download->upload_file;

        $response = new \Phalcon\Http\Response();
        $path = "app/upfiles/" . $filename;
        $filetype = filetype($path);
        $filesize = filesize($path);
        $response->setHeader("Cache-Control", 'must-revalidate, post-check=0, pre-check=0');
        $response->setHeader("Content-Description", 'File Download');
        $response->setHeader("Content-Type", 'octet-stream');
        $response->setHeader("Content-Length", $filesize);
        $response->setFileToSend($path, str_replace(" ","-",$filename), true);

But not downloading, please any one resolve it

Hi @bhanukrish it isn't a problem with Phalcon, it's a problem with browsers

You can use download attribute or read this post

Good luck