Note that rewind($fd) is exactly the same as fseek($fd, 0, SEEK_SET)
rewind() just moves the location inside the file to the beginning, nothing more. Check if your stream is "seekable" before planning to use fseek/rewind.
(PHP 4, PHP 5, PHP 7, PHP 8)
rewind — Reemplaza el puntero de fichero al inicio
Reemplaza el puntero de fichero stream
al inicio
del flujo.
Nota:
Si se ha abierto el fichero en modo de adición ("a" o "a+"), todos los datos que se escriban en este fichero serán siempre añadidos, sin importar la posición del puntero de fichero.
stream
El puntero de fichero debe ser válido y haber sido abierto correctamente por fopen().
Ejemplo #1 Ejemplo con rewind()
<?php
$handle = fopen('output.txt', 'r+');
fwrite($handle, 'Really long sentence.');
rewind($handle);
fwrite($handle, 'Foo');
rewind($handle);
echo fread($handle, filesize('output.txt'));
fclose($handle);
?>
El resultado del ejemplo sería algo similar a:
Foolly long sentence.
Note that rewind($fd) is exactly the same as fseek($fd, 0, SEEK_SET)
rewind() just moves the location inside the file to the beginning, nothing more. Check if your stream is "seekable" before planning to use fseek/rewind.