PHP文件下载

页面:
function export_course(id,name){
	  		if(!id || typeof(id)=="undefined"){
				return false;
			}
	  		window.open("<?php echo site_url()?>/course/export_course?name="+name+"&id="+id,"_blank");

	  	}
if(file_exists($dir)){
                    header('Pragma: public');
        			header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT');
        			header('Cache-Control: no-store, no-cache, must-revalidate');
        			header('Cache-Control: pre-check=0, post-check=0, max-age=0');
        			header('Content-Transfer-Encoding: binary');
        			header('Content-Encoding: none');
        			header('Content-type: ' . strtolower(trim(substr(strrchr($dir, '.'), 1, 10))));
        			header('Content-Disposition: attachment; filename="' . basename($dir) . '"');
        			header('Content-length: ' . sprintf("%u", filesize($dir)));
        			readfile($dir);               
                }else{
                    @header("Content-type: text/html; charset=utf-8");
                    echo "<script>alert('文件不存在');window.close();</script>";
                }

你可能感兴趣的:(php文件下载)