function download_file($file){ if(is_file($file)){ $length = filesize($file); $type = mime_content_type($file); $showname = ltrim(strrchr($file,'/'),'/'); header(content-description: file transfer); header('content-type: ' . $type); header('content-length:' . $length); if (preg_match('/msie/', $_server['http_user_agent'])) { //for ie header('content-disposition: attachment; filename=' . rawurlencode($showname) . ''); } else { header('content-disposition: attachment; filename=' . $showname . ''); } readfile($file); exit; } else { exit('文件已被删除!'); }}
复制代码
php