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 — Setzt die Position eines Dateizeigers auf den Anfang
Setzt den Datei-Positions-Indikator für
stream an den Anfang des Dateistreams.
Hinweis:
Wurde die Datei im Anfüge-Modus ("a" oder "a+") geöffnet, werden unabhängig von der Position des Dateizeigers alle zu schreibenden Daten angehängt.
streamDer Dateizeiger muss gültig sein und auf eine Datei zeigen, die zuvor erfolgreich durch fopen() geöffnet wurde.
Beispiel #1 Beispiel zum Überschreiben mit rewind()
<?php
$handle = fopen('output.txt', 'r+');
fwrite($handle, 'Wirklich langer Satz.');
rewind($handle);
fwrite($handle, 'Foo');
rewind($handle);
echo fread($handle, filesize('output.txt'));
fclose($handle);
?>Das oben gezeigte Beispiel erzeugt eine ähnliche Ausgabe wie:
Fooklich langer Satz.
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.