function.fpassthru.html
来自「php的帮助文档,涉及到PHP的案例和基本语法,以及实际应用内容」· HTML 代码 · 共 136 行
HTML
136 行
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><html> <head> <title>Output all remaining data on a file pointer</title> <meta http-equiv="content-type" content="text/html; charset=UTF-8"> </head> <body><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.fopen.html">fopen</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.fputcsv.html">fputcsv</a></div> <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div><hr /><div id="function.fpassthru" class="refentry"> <div class="refnamediv"> <h1 class="refname">fpassthru</h1> <p class="verinfo">(PHP 4, PHP 5)</p><p class="refpurpose"><span class="refname">fpassthru</span> — <span class="dc-title">Output all remaining data on a file pointer</span></p> </div> <div class="refsect1 description"> <h3 class="title">Description</h3> <div class="methodsynopsis dc-description"> <span class="type">int</span> <span class="methodname"><b><b>fpassthru</b></b></span> ( <span class="methodparam"><span class="type">resource</span> <tt class="parameter">$handle</tt></span> )</div> <p class="para rdfs-comment"> Reads to EOF on the given file pointer from the current position and writes the results to the output buffer. </p> <p class="para"> You may need to call <a href="function.rewind.html" class="function">rewind()</a> to reset the file pointer to the beginning of the file if you have already written data to the file. </p> <p class="para"> If you just want to dump the contents of a file to the output buffer, without first modifying it or seeking to a particular offset, you may want to use the <a href="function.readfile.html" class="function">readfile()</a>, which saves you the <a href="function.fopen.html" class="function">fopen()</a> call. </p> </div> <div class="refsect1 parameters"> <h3 class="title">Parameters</h3> <p class="para"> <dl> <dt> <span class="term"><i><tt class="parameter">handle</tt></i></span> <dd> <p class="para">The file pointer must be valid, and must point toa file successfully opened by <a href="function.fopen.html" class="function">fopen()</a> or<a href="function.fsockopen.html" class="function">fsockopen()</a> (and not yet closed by<a href="function.fclose.html" class="function">fclose()</a>).</p> </dd> </dt> </dl> </p> </div> <div class="refsect1 returnvalues"> <h3 class="title">Return Values</h3> <p class="para"> If an error occurs, <b>fpassthru()</b> returns <b><tt>FALSE</tt></b>. Otherwise, <b>fpassthru()</b> returns the number of characters read from <i><tt class="parameter">handle</tt></i> and passed through to the output. </p> </div> <div class="refsect1 examples"> <h3 class="title">Examples</h3> <p class="para"> <div class="example"> <p><b>Example #1 Using <b>fpassthru()</b> with binary files</b></p> <div class="example-contents"><div class="phpcode"><code><span style="color: #000000"><span style="color: #0000BB"><?php<br /><br /></span><span style="color: #FF8000">// open the file in a binary mode<br /></span><span style="color: #0000BB">$name </span><span style="color: #007700">= </span><span style="color: #DD0000">'./img/ok.png'</span><span style="color: #007700">;<br /></span><span style="color: #0000BB">$fp </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">, </span><span style="color: #DD0000">'rb'</span><span style="color: #007700">);<br /><br /></span><span style="color: #FF8000">// send the right headers<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Type: image/png"</span><span style="color: #007700">);<br /></span><span style="color: #0000BB">header</span><span style="color: #007700">(</span><span style="color: #DD0000">"Content-Length: " </span><span style="color: #007700">. </span><span style="color: #0000BB">filesize</span><span style="color: #007700">(</span><span style="color: #0000BB">$name</span><span style="color: #007700">));<br /><br /></span><span style="color: #FF8000">// dump the picture and stop the script<br /></span><span style="color: #0000BB">fpassthru</span><span style="color: #007700">(</span><span style="color: #0000BB">$fp</span><span style="color: #007700">);<br />exit;<br /><br /></span><span style="color: #0000BB">?></span></span></code></div> </div> </div> </p> </div> <div class="refsect1 notes"> <h3 class="title">Notes</h3> <blockquote><p><b class="note">Note</b>: When using <b>fpassthru()</b> on a binary file on Windows systems, you should make sure to open the file in binary mode by appending a <i>b</i> to the mode used in the call to <a href="function.fopen.html" class="function">fopen()</a>. <br /> You are encouraged to use the <i>b</i> flag when dealing with binary files, even if your system does not require it, so that your scripts will be more portable. <br /> </p></blockquote> </div> <div class="refsect1 seealso"> <h3 class="title">See Also</h3> <p class="para"> <ul class="simplelist"> <li class="member"><a href="function.readfile.html" class="function" rel="rdfs-seeAlso">readfile()</a></li> <li class="member"><a href="function.fopen.html" class="function" rel="rdfs-seeAlso">fopen()</a></li> <li class="member"><a href="function.popen.html" class="function" rel="rdfs-seeAlso">popen()</a></li> <li class="member"><a href="function.fsockopen.html" class="function" rel="rdfs-seeAlso">fsockopen()</a></li> </ul> </p> </div></div><hr /><div style="text-align: center;"> <div class="prev" style="text-align: left; float: left;"><a href="function.fopen.html">fopen</a></div> <div class="next" style="text-align: right; float: right;"><a href="function.fputcsv.html">fputcsv</a></div> <div class="up"><a href="ref.filesystem.html">Filesystem Functions</a></div> <div class="home"><a href="index.html">PHP Manual</a></div></div></body></html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?