重慶分公司,新征程啟航
為企業提供網站建設、域名注冊、服務器等服務
為企業提供網站建設、域名注冊、服務器等服務
php下載文件無法打開的解決辦法:1、在下載的過程中取消輸出任何非文件信息;2、將輸出的文件格式和后綴名保存一致。
葫蘆島網站制作公司哪家好,找成都創新互聯公司!從網頁設計、網站建設、微信開發、APP開發、成都響應式網站建設公司等網站項目制作,到程序開發,運營維護。成都創新互聯公司從2013年成立到現在10年的時間,我們擁有了豐富的建站經驗和運維經驗,來保證我們的工作的順利進行。專注于網站建設就選成都創新互聯公司。
推薦:《PHP視頻教程》
php下載excel文件,
1、在下載的過程中不要 輸出任何非文件信息,比如 echo log信息。 否則下載后的文件無法打開,提示格式錯誤或者文件被破壞。
2、 輸出的excel格式一定要和后綴名保存一直,否也會提示格式錯誤或者文件被破壞
代碼如下:
if (file_exists(CACHE_PATH . $file_name)){ //$this->logger->error('file realpath:'.realpath(CACHE_PATH . $file_name)); header( 'Pragma: public' ); header( 'Expires: 0' ); header( 'Content-Encoding: none' ); header( 'Cache-Control: must-revalidate, post-check=0, pre-check=0' ); header( 'Cache-Control: public' ); header( 'Content-Type: application/vnd.ms-excel'); header( 'Content-Description: File Transfer' ); header( 'Content-Disposition: attachment; filename=' . $file_name ); header( 'Content-Transfer-Encoding: binary' ); header( 'Content-Length: ' . filesize ( CACHE_PATH . $file_name ) ); readfile ( CACHE_PATH . $file_name ); } else { $this->logger->error('export model :'.$id.' 錯誤:未生產文件'); echo ''; }