<?
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=$filename");
?>
这段代码的意识是打开页面后立即出现下载保存窗口,下载的文件为$filename,如果$filename中不包含相对路径的话可以下载成功,如果包含路径的话'/'就变为了'-',我应该使用什么方法使他能够下载带有相对路径的文件。
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=$filename");
?>
这段代码的意识是打开页面后立即出现下载保存窗口,下载的文件为$filename,如果$filename中不包含相对路径的话可以下载成功,如果包含路径的话'/'就变为了'-',我应该使用什么方法使他能够下载带有相对路径的文件。
而不是从 $filename 里读出你服务器上的文件路径。
如果想要表示相对路径,你需要做的是这种:
$data=file_get_contents($filename);
这种才是读到相对路径<?
$filename = './download/d.rar';
$filesize = filesize($filename);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($filename));
header("Content-Length: ".$filesize);
$data = file_get_contents($filename);
echo $data;
?>
$filename是个参数,保存文件的路径,其中包含相对路径
你这方法你用过吗,下载的时间到挺长,下载提示成功,最后文件的长度为0,firefox ie都是这样,但是用快车可以下载
<?
$filename = './download/d.rar';
$filesize = filesize($filename);
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=".basename($filename));
header("Content-Length: ".$filesize);
$data = readfile($filename);
echo $data;
?>