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 — Riavvolge la posizione di un puntatore al file
Imposta l'indicatore di posizione del file per stream
all'inizio dello stream del file.
Nota:
Se il file è stato aperto in modalità append ("a" o "a+"), tutti i dati scritti nel file verranno sempre aggiunti in coda, indipendentemente dalla posizione del puntatore al file.
streamIl puntatore al file deve essere valido e deve puntare a un file aperto con successo da fopen().
Example #1 Esempio di sovrascrittura con rewind()
<?php
$handle = fopen('output.txt', 'r+');
fwrite($handle, 'Frase davvero lunga.');
rewind($handle);
fwrite($handle, 'Foo');
rewind($handle);
echo fread($handle, filesize('output.txt'));
fclose($handle);
?>Il precedente esempio visualizzerà qualcosa di simile a:
Foose davvero lunga.
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.