<?php
include_once $_SERVER['DOCUMENT_ROOT'] . '/include/shared-manual.inc';
$TOC = array();
$TOC_DEPRECATED = array();
$PARENTS = array();
include_once dirname(__FILE__) ."/toc/ref.stream.inc";
$setup = array (
  'home' => 
  array (
    0 => 'index.php',
    1 => 'PHP Manual',
  ),
  'head' => 
  array (
    0 => 'UTF-8',
    1 => 'zh',
  ),
  'this' => 
  array (
    0 => 'function.stream-copy-to-stream.php',
    1 => 'stream_copy_to_stream',
    2 => 'Copies data from one stream to another',
  ),
  'up' => 
  array (
    0 => 'ref.stream.php',
    1 => 'Stream 函数',
  ),
  'prev' => 
  array (
    0 => 'function.stream-context-set-params.php',
    1 => 'stream_context_set_params',
  ),
  'next' => 
  array (
    0 => 'function.stream-filter-append.php',
    1 => 'stream_filter_append',
  ),
  'alternatives' => 
  array (
  ),
  'source' => 
  array (
    'lang' => 'en',
    'path' => 'reference/stream/functions/stream-copy-to-stream.xml',
  ),
  'history' => 
  array (
  ),
);
$setup["toc"] = $TOC;
$setup["toc_deprecated"] = $TOC_DEPRECATED;
$setup["parents"] = $PARENTS;
manual_setup($setup);

contributors($setup);

?>
<div id="function.stream-copy-to-stream" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">stream_copy_to_stream</h1>
  <p class="verinfo">(PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">stream_copy_to_stream</span> &mdash; <span class="dc-title">Copies data from one stream to another</span></p>

 </div>
 <div class="refsect1 description" id="refsect1-function.stream-copy-to-stream-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="modifier">function</span> <span class="methodname"><strong>stream_copy_to_stream</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$from</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.resource.php" class="type resource">resource</a></span> <code class="parameter">$to</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><span class="type"><a href="language.types.null.php" class="type null">?</a></span><span class="type"><a href="language.types.integer.php" class="type int">int</a></span></span> <code class="parameter">$length</code><span class="initializer"> = <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong></span></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span> <code class="parameter">$offset</code><span class="initializer"> = 0</span></span><br>): <span class="type"><span class="type"><a href="language.types.integer.php" class="type int">int</a></span>|<span class="type"><a href="language.types.singleton.php" class="type false">false</a></span></span></div>

  <p class="simpara">
   Makes a copy of up to <code class="parameter">length</code> bytes
   of data from <code class="parameter">from</code> to <code class="parameter">to</code>,
   starting at the current position in <code class="parameter">from</code>, or at
   <code class="parameter">offset</code> if it is greater than <code class="literal">0</code>.
   If <code class="parameter">length</code> is <strong><code><a href="reserved.constants.php#constant.null">null</a></code></strong>, all remaining content in
   <code class="parameter">from</code> will be copied.
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.stream-copy-to-stream-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt><code class="parameter">from</code></dt>
     <dd>
      <p class="para">
       The source stream
      </p>
     </dd>
    
    
     <dt><code class="parameter">to</code></dt>
     <dd>
      <p class="para">
       The destination stream
      </p>
     </dd>
    
    
     <dt><code class="parameter">length</code></dt>
     <dd>
      <p class="para">
       Maximum bytes to copy. By default all bytes left are copied.
      </p>
     </dd>
    
    
     <dt><code class="parameter">offset</code></dt>
     <dd>
      <p class="simpara">
       If greater than <code class="literal">0</code>, the position in
       <code class="parameter">from</code>, counted from the start of the stream,
       at which to start copying: <code class="parameter">from</code> is first moved
       to that position, as with <span class="function"><a href="function.fseek.php" class="function">fseek()</a></span> and
       <strong><code><a href="filesystem.constants.php#constant.seek-set">SEEK_SET</a></code></strong>.
       If <code class="literal">0</code> (the default) or negative, no seek is
       performed and copying starts at the current position in
       <code class="parameter">from</code>.
      </p>
     </dd>
    
   </dl>
  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.stream-copy-to-stream-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   Returns the total count of bytes copied, 或者在失败时返回 <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong>.
  </p>
 </div>


 <div class="refsect1 changelog" id="refsect1-function.stream-copy-to-stream-changelog">
  <h3 class="title">更新日志</h3>
  <table class="doctable informaltable">
   
    <thead>
     <tr>
      <th>版本</th>
      <th>说明</th>
     </tr>

    </thead>

    <tbody class="tbody">
     <tr>
      <td>8.0.0</td>
      <td>
       <code class="parameter">length</code> is now nullable.
      </td>
     </tr>

    </tbody>
   
  </table>

 </div>


 <div class="refsect1 examples" id="refsect1-function.stream-copy-to-stream-examples">
  <h3 class="title">示例</h3>
  <p class="para">
   <div class="example" id="example-1">
    <p><strong>示例 #1 A <span class="function"><strong>stream_copy_to_stream()</strong></span> example</strong></p>
    <div class="example-contents">
<div class="phpcode"><pre><code style="color: #000000"><span style="color: #0000BB">&lt;?php
$src </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'http://www.example.com'</span><span style="color: #007700">, </span><span style="color: #DD0000">'r'</span><span style="color: #007700">);
</span><span style="color: #0000BB">$dest1 </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'first1k.txt'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);
</span><span style="color: #0000BB">$dest2 </span><span style="color: #007700">= </span><span style="color: #0000BB">fopen</span><span style="color: #007700">(</span><span style="color: #DD0000">'remainder.txt'</span><span style="color: #007700">, </span><span style="color: #DD0000">'w'</span><span style="color: #007700">);

echo </span><span style="color: #0000BB">stream_copy_to_stream</span><span style="color: #007700">(</span><span style="color: #0000BB">$src</span><span style="color: #007700">, </span><span style="color: #0000BB">$dest1</span><span style="color: #007700">, </span><span style="color: #0000BB">1024</span><span style="color: #007700">) . </span><span style="color: #DD0000">" bytes copied to first1k.txt\n"</span><span style="color: #007700">;
echo </span><span style="color: #0000BB">stream_copy_to_stream</span><span style="color: #007700">(</span><span style="color: #0000BB">$src</span><span style="color: #007700">, </span><span style="color: #0000BB">$dest2</span><span style="color: #007700">) . </span><span style="color: #DD0000">" bytes copied to remainder.txt\n"</span><span style="color: #007700">;

</span><span style="color: #0000BB">?&gt;</span></code></pre></div>
    </div>

   </div>
  </p>
 </div>


 <div class="refsect1 notes" id="refsect1-function.stream-copy-to-stream-notes">
  <h3 class="title">注释</h3>
  <blockquote class="note"><p><strong class="note">注意</strong>: 
   <p class="simpara">
    When <code class="parameter">from</code> is a socket stream in blocking mode,
    copying stops as soon as no data is received within the stream timeout,
    even if the end of the stream has not been reached.
    <strong><code><a href="reserved.constants.php#constant.false">false</a></code></strong> may then be returned, even though the data read until then has
    already been written to <code class="parameter">to</code>.
    This timeout defaults to
    <a href="filesystem.configuration.php#ini.default-socket-timeout" class="link">default_socket_timeout</a>
    and can be changed with <span class="function"><a href="function.stream-set-timeout.php" class="function">stream_set_timeout()</a></span>.
   </p>
  </p></blockquote>
 </div>


 <div class="refsect1 seealso" id="refsect1-function.stream-copy-to-stream-seealso">
  <h3 class="title">参见</h3>
  <p class="para">
   <ul class="simplelist">
    <li><span class="function"><a href="function.copy.php" class="function" rel="rdfs-seeAlso">copy()</a> - 拷贝文件</span></li>
   </ul>
  </p>
 </div>

</div><?php manual_footer($setup); ?>