php如何写下载的代码实例

2010-3-6 杜世伟 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();
}
}

Powered by emlog 沪ICP备2023034538号-1