stream_copy_to_stream

(no version information, might be only in CVS)

stream_copy_to_stream -- Copies data from one stream to another

Description

int stream_copy_to_stream ( resource|string source, resource|string dest [, int maxlength])

source and dest can each be either an active stream resource (opened with fopen(), fsockopen(), stream_socket_connect(), stream_socket_accept(), or another stream creation function), or a string pointing to a filename or valid wrapper resource. If source or dest are strings, PHP will attempt to open the stream from reading or writting as appropriate, perform the copy, then close it.

Makes a copy of up to maxlength bytes of data from the current position in source to dest. If maxlength is not specified, all remaining content in source will be copied. Returns the total count of bytes copied.

Example 1. stream_copy_to_stream() example

<?php
$src = fopen('http://www.example.com','r');
$dest1 = fopen('first1k.txt','w');
$dest2 = fopen('remainder.txt','w');

print stream_copy_to_stream($src, $dest1, 1024) . " bytes copied to first1k.txt\n";
print stream_copy_to_stream($src, $dest2) . " bytes copied to remainder.txt\n";

?>

Example 2. Using stream_copy_to_stream() on urls

<?php
$src = 'http://www.example.com/path/to/file.txt';
$dest = 'compress.zlib://file.txt';

print stream_copy_to_stream($src, $dest) . " bytes copied from webserver and written to compressed local file.\n";
?>

See also copy().