php readfile 函数
readfile
( PHP 4中, PHP 5中)
readfile -输出一个文件
描述
国际readfile (字符串$文件名[ ,布尔$ use_include_path =虚假[ ,资源$背景] ] )
读取文件并写入它的输出缓冲器。
参数
文件名
该文件被读取。
use_include_path
您可以使用可选的第二个参数设置为TRUE ,如果你想搜索该文件中的include_path中也。
背景
背景流资源。
返回值
返回的字节数读取文件。如果出现错误,虚假,除非返回的功能称为@ readfile ( ) ,错误信息打印。
实例
例如# 1强迫下载使用readfile ( )
$file = 'monkey.gif';
一个功能强大的B2B与B2C的购物平台,除了原本OSC功能外,增加更新的功能: 一、 取消了register_globals必须开启的限制 二、 將HTML程式碼与PHP程式碼完全分离,採用了smarty 樣板引擎 三、 每支档案includes所需函数与资料库连结,使的网页显示速度明显提升 四、 检视、购买商品群组权限设定 五、 十八岁以下禁购机制 六、 折价券购物抵扣机制 七、 礼券购物机制
if (file_exists($file)) {
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($file));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($file));
ob_clean();
flush();
readfile($file);
exit;
}
?>










