如何在代码点火器中下载 excel 和 doc 文件



我正在使用此代码,但我无法下载exceldoc文件。

public function download_document($fileName=null){
    if ($fileName) {
        $file = realpath ( "uploads/user_img" ) . "\" . $fileName;
        // check file exists    
        if (file_exists ( $file )) {
            // get file content
            $data = file_get_contents ( $file );
            //force download
            force_download ( $fileName, $data );
        } else {
            // Redirect to base url
            redirect ( base_url () );
        }
    }
}

请使用此代码:-

public function download_document($fileName=null){
    $this->load->helper('download');
    if ($fileName) {
        $file = "uploads/user_img/" . $fileName;
        // check file exists    
        if (file_exists ( $file )) {
            //force download
            force_download ( $file, NULL );
        } else {
            // Redirect to base url
            redirect ( base_url () );
        }
    }
}

请点击以下链接。

https://www.codeigniter.com/userguide3/helpers/download_helper.html

最新更新