In this article, you will learn how to communicate or pass data between streams in PHP. The PHP stream_filter_append() function copies data from one stream to another.
STREAM_COPY_TO STREAM() function in php?
stream_copy_to_stream(src, dest, maxlength, offset)
Parameter | Description |
---|---|
src | Required. Specifies the source stream to copy data from |
dest | Required. Specifies the destination stream to copy data to |
maxlength | Optional. Specifies the maximum bytes to copy |
offset | Optional. Specifies the offset where to start to copy data |
examples of the STREAM_COPY_TO STREAM() function
Example 1. In this example, we copy 1024 bytes of data from one stream to another.
<?php
$src = fopen("test1.txt", "r");
$dest = fopen("test2.txt", "w");
// Copy 1024 bytes to test2.txt
echo stream_copy_to_stream($src, $dest, 1024) . " bytes copied to test2.txt";
?>