•  0
    Phalcon

    Download file in Phalcon

      Admin     7232        0        Report content

    PHP function to download file in Phalcon

        use PhalconHttpResponse;
        public function downloadAction($file)
        { 
            $response = new Response();
            $path = 'path/to-your-file/'.$file;
            $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", $filetype);
            $response->setHeader("Content-Length", $filesize);
            $response->setFileToSend($path, str_replace(" ","-",$file), true);
            $response->send();
            die();
        }
    


    Alternatively,

        public function downloadAction($file)
        { 
            $path = 'path/to-your-file/'.$file;
            $filetype = filetype($path);
            $filesize = filesize($path);
            header("Cache-Control: must-revalidate, post-check=0, pre-check=0");
            header('Content-Description: File Download');
            header('Content-type: '.$filetype);
            header('Content-length: ' . $filesize);
            header('Content-Disposition: attachment; filename="'.$file.'"');
            readfile($path);
            die();*/
         }
    

     

     


Leave a Comment

Please Login to insert comment.

 

Facebook Conversations