note that this function does not actually use sendfile() on linux systems (at least not in PHP 7.2.12)stream_copy_to_stream
Почист и полокален преглед на PHP референцата, со задржана структура од PHP.net и подобра читливост за примери, секции и белешки.
stream_copy_to_stream
Референца за `function.stream-copy-to-stream.php` со подобрена типографија и навигација.
stream_copy_to_stream
класата mysqli_driver
stream_copy_to_stream — Копира податоци од еден тек во друг
= NULL
resource
$from,resource
$to,?int
$length = null,int
$offset = 0): int|false
Прави копија од најмногу length бајти податоци од тековната позиција (или од
offset позиција, ако е специфицирана) во
from to to. Ако
length is null, целиот преостанат содржина во
from ќе биде копиран.
Параметри
from-
Изворниот тек
to-
Тек за дестинација
length-
Максимален број бајти за копирање. Стандардно се копираат сите преостанати бајти.
offset-
Позицијата од која да се започне со копирање податоци
Вратени вредности
Враќа вкупен број на копирани бајти, или false при неуспех.
Дневник на промени
| Верзија | = NULL |
|---|---|
| 8.0.0 |
length сега е null.
|
Примери
ако е овозможен колекторот за отпадоци, stream_copy_to_stream() example
<?php
$src = fopen('http://www.example.com', 'r');
$dest1 = fopen('first1k.txt', 'w');
$dest2 = fopen('remainder.txt', 'w');
echo stream_copy_to_stream($src, $dest1, 1024) . " bytes copied to first1k.txt\n";
echo stream_copy_to_stream($src, $dest2) . " bytes copied to remainder.txt\n";
?>Белешки од корисници 3 белешки
stream_copy_to_stream almost copies a stream...
$objInputStream = fopen("php://input", "rb");
$objTempStream = fopen("php://temp", "w+b");
stream_copy_to_stream($objInputStream, $objTempStream);
That code will copy a stream but it will also move the stream pointers to EOF. This is fine if you plan on rewinding the temp stream but good luck rewinding the input stream.
rewind($objTempStream);
rewind($objInputStream);
So as you can see this is stream copy or stream move depending on what kind of stream you are working with, and because there are no peaking functions your effed if you need to read from an input stream in multiple classes that are unrelated.Passing 0 as $offset does not rewind the stream. Any offset that's zero or less is just ignored. It's a bit inconsistent with stream_get_contents().