public function sendFile($fileName,$content,$mimeType=null,$terminate=true) { if($mimeType===null) { if(($mimeType=CFileHelper::getMimeTypeByExtension($fileName))===null) $mimeType='text/plain'; } header('Pragma: public'); header('Expires: 0'); header('Cache-Control: must-revalidate, post-check=0, pre-check=0'); header("Content-type: $mimeType"); if(ini_get("output_handler")=='') header('Content-Length: '.(function_exists('mb_strlen') ? mb_strlen($content,'8bit') : strlen($content))); header("Content-Disposition: attachment; filename=\"$fileName\""); header('Content-Transfer-Encoding: binary'); if($terminate) { // clean up the application first because the file downloading could take long time // which may cause timeout of some resources (such as DB connection) Yii::app()->end(0,false); echo $content; exit(0); } else echo $content; } public function xSendFile($filePath, $options=array()) { if(!is_file($filePath)) return false; if(!isset($options['saveName'])) $options['saveName']=basename($filePath); if(!isset($options['mimeType'])) { if(($options['mimeType']=CFileHelper::getMimeTypeByExtension($filePath))===null) $options['mimeType']='text/plain'; } if(!isset($options['xHeader'])) $options['xHeader']='X-Sendfile'; header('Content-type: '.$options['mimeType']); header('Content-Disposition: attachment; filename="'.$options['saveName'].'"'); header(trim($options['xHeader']).': '.$filePath); if(!isset($options['terminate']) || $options['terminate']) Yii::app()->end(); return true; }
YII Framework学习之request与response用法(基于CHttpReq(3)
内容版权声明:除非注明,否则皆为本站原创文章。
转载注明出处:https://www.heiqu.com/46c5ea7a78fbab6b34e851824cd6355f.html