我正在使用此代码,但无法下载excel
和doc
文件。
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 () );
}
}
}
答案 0 :(得分:0)
请使用以下代码:-
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