位置: 编程技术 - 正文

PHP:readfile()的用法_Filesystem函数(php readfile)

编辑:rootadmin
readfile

推荐整理分享PHP:readfile()的用法_Filesystem函数(php readfile),希望有所帮助,仅作参考,欢迎阅读内容。

文章相关热门搜索词:php readdir,php file_append,php readfile,php read,php readdir,php read,php readdir,php readfile,内容如对您有帮助,希望把文章链接给更多的朋友!

(PHP 4, PHP 5)

readfile — 输出一个文件

说明 int readfile ( string $filename [, bool $use_include_path = false [, resource $context ]] )

读入一个文件并写入到输出缓冲。

参数

filename

要读取的文件名。

use_include_path

如果也想在 include_path 中搜索文件,可以使用可选的第二个参数并将其设为 TRUE。

context

A context stream resource.

返回值 PHP:readfile()的用法_Filesystem函数(php readfile)

返回从文件中读入的字节数。如果出错返回 FALSE 并且除非是以 @readfile() 形式调用,否则会显示错误信息。

范例

Example #1 Forcing a download using readfile()

<?php$file='monkey.gif';if(file_exists($file)){header('Content-Description:FileTransfer');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');header('Pragma:public');header('Content-Length:'.filesize($file));ob_clean();flush();readfile($file);exit;}?>

以上例程的输出类似于:

注释

Note:

readfile() will not present any memory issues, even when sending large files, on its own. If you encounter an out of memory error ensure that output buffering is off with ob_get_level().

Tip

如已启用fopen 包装器,在此函数中, URL 可作为文件名。关于如何指定文件名详见 fopen()。各种wapper 的不同功能请参见 支持的协议和封装协议,注意其用法及其可提供的预定义变量。

Note: 在 PHP 5.0.0中增加了对上下文(Context)的支持。有关上下文(Context)的说明参见Streams。

参见

fpassthru() - 输出文件指针处的所有剩余数据 file() - 把整个文件读入一个数组中 fopen() - 打开文件或者 URL include - include require - require virtual() - 执行 Apache 子请求 file_get_contents() - 将整个文件读入一个字符串 支持的协议和封装协议

PHP:pclose()的用法_Filesystem函数 pclose(PHP4,PHP5)pclose关闭进程文件指针说明intpclose(resource$handle)关闭用popen()打开的指向管道的文件指针。参数handle文件指针必须有效,且必须是成功调用pop

PHP:readlink()的用法_Filesystem函数 readlink(PHP4,PHP5)readlink返回符号连接指向的目标说明stringreadlink(string$path)readlink()和同名的C函数做同样的事,返回符号连接的内容。参数path链接符号的路

PHP:pathinfo()的用法_Filesystem函数 pathinfo(PHP4=4.0.3,PHP5)pathinfo返回文件路径的信息说明mixedpathinfo(string$path[,int$options=PATHINFO_DIRNAME|PATHINFO_BASENAME|PATHINFO_EXTENSION|PATHINFO_FILENAME])pathinfo()返回一个

本文链接地址:https://www.jiuchutong.com/biancheng/285182.html 转载请保留说明!

上一篇:PHP:popen()的用法_Filesystem函数(php proc_open)

下一篇:PHP:pclose()的用法_Filesystem函数(php pulsar)

免责声明:网站部分图片文字素材来源于网络,如有侵权,请及时告知,我们会第一时间删除,谢谢! 邮箱:opceo@qq.com

鄂ICP备2023003026号

网站地图: 企业信息 工商信息 财税知识 网络常识 编程技术

友情链接: 武汉网站建设 电脑维修 湖南楚通运网络