File download functionality at CakePHP 2.0



  /*
     *  function name admin_download(
     *     Fiile Name,
     *     Folder Path
     *  )
     *  Admin Panel download
     */

    public function admin_download($filename='', $dir_path = '') {
        $name = pathinfo($filename, PATHINFO_FILENAME);
        $ext = pathinfo($filename, PATHINFO_EXTENSION);
        $this->viewClass = 'Media';
        $params = array(
            'id' => $filename,
            'name' => $name,
            'download' => true,
            'extension' => $ext,
            'mimeType' => array(
                "docm" => "application/vnd.ms-word.document.macroEnabled.12",
                "docx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
                "dotm" => "application/vnd.ms-word.template.macroEnabled.12",
                "dotx" => "application/vnd.openxmlformats-officedocument.wordprocessingml.template",
                "potm" => "application/vnd.ms-powerpoint.template.macroEnabled.12",
                "potx" => "application/vnd.openxmlformats-officedocument.presentationml.template",
                "ppam" => "application/vnd.ms-powerpoint.addin.macroEnabled.12",
                "ppsm" => "application/vnd.ms-powerpoint.slideshow.macroEnabled.12",
                "ppsx" => "application/vnd.openxmlformats-officedocument.presentationml.slideshow",
                "pptm" => "application/vnd.ms-powerpoint.presentation.macroEnabled.12",
                "pptx" => "application/vnd.openxmlformats-officedocument.presentationml.presentation",
                "xlam" => "application/vnd.ms-excel.addin.macroEnabled.12",
                "xlsb" => "application/vnd.ms-excel.sheet.binary.macroEnabled.12",
                "xlsm" => "application/vnd.ms-excel.sheet.macroEnabled.12",
                "xlsx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
                "xltm" => "application/vnd.ms-excel.template.macroEnabled.12",
                "xltx" => "application/vnd.openxmlformats-officedocument.spreadsheetml.template",
                "pdf" => "application/pdf"
            ),
            'path' => WWW_ROOT . DS . $dir_path . DS
        );
        $this->set($params);
    }

Advertisements

One response to “File download functionality at CakePHP 2.0

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s