站长论坛

标题: php如何写下载的代码实例 [打印本页]

作者: tznktg    时间: 2007-10-4 15:11
标题: php如何写下载的代码实例
case 'down':
                if($_GET[file]){
                        $real_file_path = "$currdir/$_GET[file]";
                        if(is_file($real_file_path))
                        {
                                  @set_time_limit(600);
                                 $filename = basename($real_file_path);
                                $filesize = filesize($real_file_path);

                               header("Content-Type: application/force-download; name=\"$filename\"");
                                header("Content-Transfer-Encoding: binary");
                                header("Content-Length: $filesize");
                                header("Content-Disposition: attachment; filename=\"$filename\"");
                                header("Expires: 0");
                                header("Cache-Control: no-cache, must-revalidate");
                                header("Pragma: no-cache");

                                readfile("$real_file_path");

                                //print("<script>window.close();</script>");
                                exit();
                        }
                }




欢迎光临 站长论坛 (https://tzlink.com/bbs/) Powered by Discuz! X3.2