PHP强制下载文件的实现


PHP #文件2014-04-09 22:54

这个简单,参考下面的代码吧。

<?php
	$file_dir = "./";	
	$name = "yige.org.txt";
	$file = fopen($file_dir.$name,"r"); 
	Header("Content-type: application/octet-stream");
	Header("Accept-Ranges: bytes");
	Header("Accept-Length: ".filesize($file_dir . $name));
	Header("Content-Disposition: attachment; filename=".$name);
	echo fread($file, filesize($file_dir.$name));
	fclose($file);


相关文章

粤ICP备11097351号-1