如题。
我想用php下载服务器某一个文件夹下的文件。
实现代码如下【downfile.php】:
[code="java"]
$path = "d:\wwww\program\";
$filename="test.rar";
$durl = $path.$filename;
//$filename = 'phpcms2008_o2abf32efj883c91a.iso';
$file = @fopen($durl, 'r');
header("Content-Type: application/octet-stream");
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($durl));
header("Content-Disposition: attachment; filename=".$filename);
echo fread($file,filesize($durl));
fclose($file);
[/code]
提示错误
Warning: Cannot modify header information - headers already sent by (output started at D:\WebRoot\oem\style\default\header.php:1) in D:\WebRoot\oem\module\download\downfile.php on line 32
我就根据网上找到的方法试了一下。我的只能通过 修改php.ini 来达到目的。output_buffering=on。
请问还有其他的方法吗?
我还想用ob_start();
[code="java"]
<?php ob_start(); ?>
<?php
/*
header("Accept-Ranges: bytes");
header("Accept-Length: ".filesize($durl));
header("Content-Disposition: attachment; filename=".$filename);
echo fread($file,filesize($durl));
fclose($file);
ob_end_flush();
?>
[/code]结果还是报错。请问为什么?
你的解决办法就是最正确的了,MS已经找不到更好的办法了 :idea:
这个报错就是说在header之前不能有任何的输出.